[/trunk] Changeset 23 by mikael
* Don't crash when receiving a message with more than 50 lines!
--- 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 */