It looks good, thx Christophe ! On Sunday, May 18, 2014, Christophe <christophe.cu...@free.fr> wrote:
> From: Christophe CURIS <christophe.cu...@free.fr <javascript:;>> > > The original code did have a few weaknesses, including: > - possible buffer overflow, if the translation was too long; > - possible crash, if either instance or class is NULL but not both > > Now the appropriate length is calculated (not counting on a margin) and the > string is generated with the available elements. > > As a side note, the variable was renamed from 'tmp' to 'title' for clarity. > > This was highlighted by cppcheck (thanks to David Maciejak) and by > Coverity (bug #50078). > > Signed-off-by: Christophe CURIS <christophe.cu...@free.fr <javascript:;>> > --- > src/dialog.c | 40 +++++++++++++++++++++++++++++----------- > 1 file changed, 29 insertions(+), 11 deletions(-) > > diff --git a/src/dialog.c b/src/dialog.c > index da126ae..1102747 100644 > --- a/src/dialog.c > +++ b/src/dialog.c > @@ -1011,22 +1011,40 @@ Bool wIconChooserDialog(WScreen *scr, char **file, > const char *instance, const c > XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0); > > { > - char *tmp; > - int len = (instance ? strlen(instance) : 0) > - + (class ? strlen(class) : 0) + 32; > + static const char *prefix = NULL; > + char *title; > + int len; > WMPoint center; > > - tmp = wmalloc(len); > - > - if (tmp && (instance || class)) > - snprintf(tmp, len, "%s [%s.%s]", _("Icon > Chooser"), instance, class); > - else > - strcpy(tmp, _("Icon Chooser")); > + if (prefix == NULL) > + prefix = _("Icon Chooser"); > + > + len = strlen(prefix) > + + 2 // " [" > + + (instance ? strlen(instance) : 0) > + + 1 // "." > + + (class ? strlen(class) : 0) > + + 1 // "]" > + + 1; // final NUL > + > + title = wmalloc(len); > + strcpy(title, prefix); > + > + if (instance || class) { > + strcat(title, " ["); > + if (instance != NULL) > + strcat(title, instance); > + if (instance && class) > + strcat(title, "."); > + if (class != NULL) > + strcat(title, class); > + strcat(title, "]"); > + } > > center = getCenter(scr, 450, 280); > > - wwin = wManageInternalWindow(scr, parent, None, tmp, > center.x, center.y, 450, 280); > - wfree(tmp); > + wwin = wManageInternalWindow(scr, parent, None, title, > center.x, center.y, 450, 280); > + wfree(title); > } > > /* put icon paths in the list */ > -- > 1.9.2 > > > -- > To unsubscribe, send mail to > wmaker-dev-unsubscr...@lists.windowmaker.org<javascript:;> > . >