Mercurial > hg
changeset 8:4c1affca7aea
[/trunk] Changeset 23 by mikael
* Don't crash when receiving a message with more than 50 lines!
author | mikael |
---|---|
date | Sat, 19 Mar 2005 12:45:11 +0000 |
parents | f616c617e46d |
children | 455ab6bc14ac |
files | mcabber/utils.c |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 */