On 2005-05-13 08:33, Andre Guibert de Bruet <andy_at_siliconlandmark.com> wrote: > On Thu, 12 May 2005, Giorgos Keramidas wrote: > >Does the diff below look like a good way to fix this? > > > >%%% > >+char * > >+trim_header(text) > >+ > >+char *text; > >+ > >+{ > >+ char *s; > >+ int width; > >+ > >+ s = NULL; > > Setting s to NULL is useless because malloc returns either NULL on failure > or a pointer to the allocated memory segment. Setting s to NULL unconditionally means that even if the if block right below doesn't run, the pointer *WILL* be initialized to something meaningful. > > >+ width = display_width; > >+ header_length = strlen(text); > >+ if (header_length >= width) { This part won't run all the time. If it doesn't, then `s' could potentially hold garbage from the stack and the callers of trim_header() would find it very surprising that their non-NULL pointer causes a segfault in free() :-) > Other than that pet-peeve, the patch looks good to me... Cool :)Received on Fri May 13 2005 - 10:39:56 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:34 UTC