# HG changeset patch # User mikael # Date 1111236311 0 # Node ID 4c1affca7aea01dfd0a142751f0f0eccb9d0f6a8 # Parent f616c617e46d2eaafb75e65d911d872e034cbc54 [/trunk] Changeset 23 by mikael * Don't crash when receiving a message with more than 50 lines! diff -r f616c617e46d -r 4c1affca7aea mcabber/utils.c --- a/mcabber/utils.c Sat Mar 19 12:16:06 2005 +0000 +++ b/mcabber/utils.c Sat Mar 19 12:45:11 2005 +0000 @@ -56,9 +56,10 @@ char *aux2; char **submsgs; char *buffer = (char *) malloc(strlen(message) * 2); + int maxnlines = 50; int i = 0; - submsgs = (char **) malloc(50 * sizeof(char *)); /* limitamos, a priori, el maximo de lineas devueltas... */ + submsgs = (char **) malloc(maxnlines * sizeof(char *)); running = strdup(message); aux2 = strdup(message); @@ -84,6 +85,12 @@ i++; /*aumentamos numero de mensajillos */ aux2 += strlen(buffer) + 1; /*eliminamos texto particionado */ sprintf(running, "%s", aux2); /*y lo copiamos de nuevo a la string de "curro" */ + + // Check if we have allocated enough space + if (i >= maxnlines) { + maxnlines += 50; + submsgs = (char **) realloc(submsgs, maxnlines * sizeof(char *)); + } aux = index(running, '\n'); /* is there is a CR now? */ } /* last part of the message */