comparison mcabber/utils.c @ 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 4dcabf02f474
children 7eeda3a06b21
comparison
equal deleted inserted replaced
7:f616c617e46d 8:4c1affca7aea
54 char *running; 54 char *running;
55 char *aux; 55 char *aux;
56 char *aux2; 56 char *aux2;
57 char **submsgs; 57 char **submsgs;
58 char *buffer = (char *) malloc(strlen(message) * 2); 58 char *buffer = (char *) malloc(strlen(message) * 2);
59 int maxnlines = 50;
59 int i = 0; 60 int i = 0;
60 61
61 submsgs = (char **) malloc(50 * sizeof(char *)); /* limitamos, a priori, el maximo de lineas devueltas... */ 62 submsgs = (char **) malloc(maxnlines * sizeof(char *));
62 63
63 running = strdup(message); 64 running = strdup(message);
64 aux2 = strdup(message); 65 aux2 = strdup(message);
65 66
66 aux = index(running, '\n'); /* is there a CR? */ 67 aux = index(running, '\n'); /* is there a CR? */
82 submsgs[i] = (char *) malloc(strlen(buffer) + 1); /*reservamos memoria */ 83 submsgs[i] = (char *) malloc(strlen(buffer) + 1); /*reservamos memoria */
83 strcpy(submsgs[i], buffer); /*copiamos el buffer de arriba */ 84 strcpy(submsgs[i], buffer); /*copiamos el buffer de arriba */
84 i++; /*aumentamos numero de mensajillos */ 85 i++; /*aumentamos numero de mensajillos */
85 aux2 += strlen(buffer) + 1; /*eliminamos texto particionado */ 86 aux2 += strlen(buffer) + 1; /*eliminamos texto particionado */
86 sprintf(running, "%s", aux2); /*y lo copiamos de nuevo a la string de "curro" */ 87 sprintf(running, "%s", aux2); /*y lo copiamos de nuevo a la string de "curro" */
88
89 // Check if we have allocated enough space
90 if (i >= maxnlines) {
91 maxnlines += 50;
92 submsgs = (char **) realloc(submsgs, maxnlines * sizeof(char *));
93 }
87 aux = index(running, '\n'); /* is there is a CR now? */ 94 aux = index(running, '\n'); /* is there is a CR now? */
88 } 95 }
89 /* last part of the message */ 96 /* last part of the message */
90 if (strlen(aux2) > 0) { 97 if (strlen(aux2) > 0) {
91 submsgs[i] = (char *) malloc(strlen(aux2) + 1); 98 submsgs[i] = (char *) malloc(strlen(aux2) + 1);