diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -253,20 +253,17 @@ char * ExpandFilename(const char *name) { char *newname; + int retval; if (name[0] != '~') return strdup(name); - newname = malloc((size_t) HomeLen + strlen(name) + 2); - if (!newname) { + retval = asprintf(&newname, "%s/%s", Home, &name[1]); + if (retval == -1 || !newname) { twmWarning("unable to allocate %lu bytes to expand filename %s/%s", (unsigned long) HomeLen + (unsigned long) strlen(name) + 2, Home, &name[1]); } - else { - (void) sprintf(newname, "%s/%s", Home, &name[1]); - } - return newname; } @@ -348,23 +345,22 @@ FindBitmap(const char *name, unsigned *widthp, unsigned *heightp) pm = XmuLocateBitmapFile(ScreenOfDisplay(dpy, Scr->screen), bigname, NULL, 0, (int *) widthp, (int *) heightp, &HotX, &HotY); if (pm == None && Scr->IconDirectory && bigname[0] != '/') { - free(bigname); + free (bigname); /* * Attempt to find icon in old IconDirectory (now obsolete) */ - bigname = malloc(strlen(name) + strlen(Scr->IconDirectory) + 2); + asprintf(&bigname, "%s/%s", Scr->IconDirectory, name); if (!bigname) { twmWarning("unable to allocate memory for \"%s/%s\"", Scr->IconDirectory, name); return None; } - (void) sprintf(bigname, "%s/%s", Scr->IconDirectory, name); - if (XReadBitmapFile(dpy, Scr->Root, bigname, widthp, heightp, &pm, - &HotX, &HotY) != BitmapSuccess) { + if (XReadBitmapFile (dpy, Scr->Root, bigname, widthp, heightp, &pm, + &HotX, &HotY) != BitmapSuccess) { pm = None; } } - free(bigname); + free (bigname); if (pm == None) { twmWarning("unable to find bitmap \"%s\"", name); } |