summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/util.c b/src/util.c
index 52f6148..e25206a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -255,20 +255,17 @@ char *
ExpandFilename(const char *name)
{
char *newname;
+ int retval;
if (name[0] != '~')
return strdup(name);
- newname = (char *) 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;
}
@@ -358,16 +355,14 @@ FindBitmap(const char *name, unsigned *widthp, unsigned *heightp)
/*
* Attempt to find icon in old IconDirectory (now obsolete)
*/
- bigname = (char *)
- 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) {
+ &HotX, &HotY) != BitmapSuccess) {
pm = None;
}
}