<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40013 >
> [wsimpson - Mon Jan 14 02:21:34 2008]: > > Discovered more egregious lack of checking buffer sizes, this time > loading > help text data from the file. Instead, there's a long_buffer[64000], > ... Given that so much text is written (needing a 64K buffer), and that there are so many occurences of cat_snprintf (that rather than re- writing each call to strlcat, a macro CATLSTR is need just to avoid changing the order of arguments in all places it is used), would it not seem terribly inefficient to have to find the end of the string on every single call to a cat/CAT* function? Would it not be just as simple to code (a macro is even used already) to keep a pointer to the end of the buffer, which would be incremented by the number of bytes written, just as the remaining space in the buffer would be decremented? Why not just make a dynamic buffer type, and do any with all this gigantic static buffer nonsense? E.g. dynamic_buffer *buf = dynamic_buffer_new(1024); /* initial size 1024 */ ... dynamic_buffer_cat_snprintf(buf, ...); dynamic_buffer_strcat(buf, ...); /* size doubles if needed */ ... dynamic_buffer_free(buf); etc. I say this because I have come in contact with many places that would benefit from such buffers (but certainly you would know better than I)... _______________________________________________ Freeciv-dev mailing list [email protected] https://mail.gna.org/listinfo/freeciv-dev
