[FIX] Do NOT use strlen in a loop

Never. Do. This. Never. It should never cross your mind. Doing so will
punish you. Basic computer science concepts will tell you it's O(n^2).
And it WILL actually matter. Never. Never. Never. Never. Never. Never.
            NEVER FUCKING EVER DO THAT EVER AGAIN.
            NEVER FUCKING EVER DO THAT EVER AGAIN.
            NEVER FUCKING EVER DO THAT EVER AGAIN.
            NEVER FUCKING EVER DO THAT EVER AGAIN.
            NEVER FUCKING EVER DO THAT EVER AGAIN.
Anyways, also fixes licensing year. On est en octobre et il comprend
toujours pas qu'on est plus en 2023.
This commit is contained in:
LDA 2024-10-11 19:49:19 +02:00
commit 147e430a47
5 changed files with 33 additions and 21 deletions

View file

@ -91,9 +91,10 @@ MatrixCreateMedia(char *mxc, char *body, char *mime, FileInfo *info)
matrix_type = "m.file";
if (mime)
{
size_t i;
size_t i, len;
mime_type = StrDuplicate(mime);
for (i = 0; i < strlen(mime); i++)
len = strlen(mime);
for (i = 0; i < len; i++)
{
if (mime_type[i] == '/')
{

View file

@ -79,7 +79,7 @@ Main(Array *args, HashMap *env)
);
ParseePrintASCII();
Log(LOG_INFO, "=======================");
Log(LOG_INFO, "(C)opyright 2023 LDA");
Log(LOG_INFO, "(C)opyright 2024 LDA");
Log(LOG_INFO, "(This program is free software, see LICENSE.)");
LogConfigIndent(LogConfigGlobal());
@ -153,7 +153,6 @@ Main(Array *args, HashMap *env)
}
}
Free(opts);
ParseeSetThreads(xmpp, http);
}
if (verbose >= PARSEE_VERBOSE_COMICAL)
@ -167,6 +166,7 @@ Main(Array *args, HashMap *env)
{
goto end;
}
ParseeSetThreads(xmpp, http);
Log(LOG_NOTICE, "Connecting to XMPP...");

View file

@ -147,14 +147,15 @@ char *
ParseeEncodeJID(const ParseeConfig *c, char *jid, bool trim)
{
char *ret, *tmp;
size_t i;
size_t i, len;
if (!c || !jid)
{
return NULL;
}
ret = StrConcat(2, c->namespace_base, "_l_");
for (i = 0; i < strlen(jid); i++)
len = strlen(jid);
for (i = 0; i < len; i++)
{
char cpy = jid[i];
char cs[4] = { 0 };
@ -193,7 +194,7 @@ char *
ParseeGetLocal(char *mxid)
{
char *cpy;
size_t i;
size_t i, len;
if (!mxid)
{
return NULL;
@ -203,12 +204,14 @@ ParseeGetLocal(char *mxid)
return StrDuplicate(mxid);
}
mxid++;
cpy = Malloc(strlen(mxid) + 1);
memset(cpy, '\0', strlen(mxid) + 1);
memcpy(cpy, mxid, strlen(mxid));
len = strlen(mxid);
for (i = 0; i < strlen(mxid); i++)
mxid++;
cpy = Malloc(len + 1);
memset(cpy, '\0', len + 1);
memcpy(cpy, mxid, len);
for (i = 0; i < len; i++)
{
if (cpy[i] == ':')
{
@ -224,15 +227,16 @@ char *
ParseeEncodeMXID(char *mxid)
{
char *ret;
size_t i, j;
size_t i, j, len;
if (!mxid)
{
return NULL;
}
/* Worst case scenario of 3-bytes the char */
ret = Malloc(strlen(mxid) * 3 + 1);
for (i = 0, j = 0; i < strlen(mxid); i++)
len = strlen(mxid);
ret = Malloc(len * 3 + 1);
for (i = 0, j = 0; i < len; i++)
{
char src = mxid[i];
@ -372,14 +376,15 @@ char *
ParseeTrimJID(char *jid)
{
char *ret;
size_t i;
size_t i, len;
if (!jid)
{
return NULL;
}
ret = StrDuplicate(jid);
for (i = 0; i < strlen(ret); i++)
len = strlen(ret);
for (i = 0; i < len; i++)
{
if (ret[i] == '/')
{

View file

@ -114,14 +114,19 @@ XMLCDecode(Stream *stream, bool autofree, bool html)
void
XMLEncodeString(Stream *stream, char *data)
{
size_t i;
size_t i, len;
if (!stream || !data)
{
return;
}
for (i = 0; i < strlen(data); i++)
/* TODO: I should write a "Parsee Best Practice" guideline and make sure
* people understand to NOT constantly recompute lengths parameter on
* these kinds of loops. ArraySize is fine(since its indirection), but
* operations like strlen take time! */
len = strlen(data);
for (i = 0; i < len; i++)
{
char c = data[i];
if (c == '<')

View file

@ -295,7 +295,7 @@ static bool
XMLookahead(XMLexer *lexer, const char *str, bool skip)
{
int *stack;
size_t top, i;
size_t top, i, len;
ssize_t ntop;
bool ret = false;
if (!lexer || !str)
@ -304,9 +304,10 @@ XMLookahead(XMLexer *lexer, const char *str, bool skip)
}
top = 0;
stack = Malloc(strlen(str) * sizeof(*stack));
len = strlen(str);
stack = Malloc(len * sizeof(*stack));
for (i = 0; i < strlen(str); i++)
for (i = 0; i < len; i++)
{
char c = str[i];
int getc = XMLGetc(lexer);