summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu.herrb@laas.fr>2008-04-19 17:53:56 +0200
committerMatthieu Herrb <matthieu@bluenote.herrb.net>2008-04-19 17:53:56 +0200
commit22290b3051b90ee8b791be23a6d82595a06704ac (patch)
tree67557abe482307abda545bc9513f38c1119064ba
parentbe2debd6e9f6a27bf574435591e38c9590af0f62 (diff)
Itojun's patches to remove sprintf(), strcpy() and strcat().
-rw-r--r--src/gram.y3
-rw-r--r--src/iconmgr.c4
-rw-r--r--src/menus.c16
-rw-r--r--src/parse.c4
-rw-r--r--src/resize.c2
-rw-r--r--src/session.c18
-rw-r--r--src/util.c14
7 files changed, 27 insertions, 34 deletions
diff --git a/src/gram.y b/src/gram.y
index d623ddb..fcfbf62 100644
--- a/src/gram.y
+++ b/src/gram.y
@@ -649,8 +649,7 @@ button : BUTTON number { $$ = $2;
}
;
-string : STRING { ptr = (char *)malloc(strlen($1)+1);
- strcpy(ptr, $1);
+string : STRING { ptr = strdup($1);
RemoveDQuote(ptr);
$$ = ptr;
}
diff --git a/src/iconmgr.c b/src/iconmgr.c
index b90b665..9eebf9f 100644
--- a/src/iconmgr.c
+++ b/src/iconmgr.c
@@ -97,8 +97,8 @@ void CreateIconManagers()
JunkX, JunkY, p->width, p->height, 1,
Scr->Black, background);
- sprintf(str, "%s Icon Manager", p->name);
- sprintf(str1, "%s Icons", p->name);
+ snprintf(str, sizeof(str), "%s Icon Manager", p->name);
+ snprintf(str1, sizeof(str1), "%s Icons", p->name);
if (p->icon_name)
icon_name = p->icon_name;
else
diff --git a/src/menus.c b/src/menus.c
index d91dd24..eaf9cf9 100644
--- a/src/menus.c
+++ b/src/menus.c
@@ -1983,8 +1983,8 @@ ExecuteFunction(int func, char *action, Window w, TwmWindow *tmp_win,
break;
case F_CUT:
- strcpy(tmp, action);
- strcat(tmp, "\n");
+ strlcpy(tmp, action, sizeof(tmp));
+ strlcat(tmp, "\n", sizeof(tmp));
XStoreBytes(dpy, tmp, strlen(tmp));
break;
@@ -2358,7 +2358,11 @@ Execute(char *s)
oldDisplay[0] = '\0';
doisplay=getenv("DISPLAY");
if (doisplay)
- strcpy (oldDisplay, doisplay);
+ if (strlcpy (oldDisplay, doisplay, sizeof(oldDisplay)) >=
+ sizeof(oldDisplay)) {
+ /* some error report? */
+ return;
+ }
/*
* Build a display string using the current screen number, so that
@@ -2368,8 +2372,8 @@ Execute(char *s)
*/
colon = strrchr (ds, ':');
if (colon) { /* if host[:]:dpy */
- strcpy (buf, "DISPLAY=");
- strcat (buf, ds);
+ strlcpy (buf, "DISPLAY=", sizeof(buf));
+ strlcat (buf, ds, sizeof(buf));
colon = buf + 8 + (colon - ds); /* use version in buf */
dot1 = strchr (colon, '.'); /* first period after colon */
if (!dot1) dot1 = colon + strlen (colon); /* if not there, append */
@@ -2381,7 +2385,7 @@ Execute(char *s)
(void) system (s);
if (restorevar) { /* why bother? */
- (void) sprintf (buf, "DISPLAY=%s", oldDisplay);
+ (void) snprintf (buf, sizeof(buf), "DISPLAY=%s", oldDisplay);
putenv (buf);
}
}
diff --git a/src/parse.c b/src/parse.c
index 88b0b08..c89da98 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -183,8 +183,8 @@ int ParseTwmrc (char *filename)
if (home) {
homelen = strlen (home);
cp = tmpfilename;
- (void) sprintf (tmpfilename, "%s/.twmrc.%d",
- home, Scr->screen);
+ (void) snprintf (tmpfilename, sizeof(tmpfilename),
+ "%s/.twmrc.%d", home, Scr->screen);
break;
}
}
diff --git a/src/resize.c b/src/resize.c
index 2f114e1..a6950d7 100644
--- a/src/resize.c
+++ b/src/resize.c
@@ -514,7 +514,7 @@ DisplaySize(TwmWindow *tmp_win, int width, int height)
dheight /= tmp_win->hints.height_inc;
}
- (void) sprintf (str, " %4d x %-4d ", dwidth, dheight);
+ (void) snprintf (str, sizeof(str), " %4d x %-4d ", dwidth, dheight);
XRaiseWindow(dpy, Scr->SizeWindow);
MyFont_ChangeGC(Scr->DefaultC.fore, Scr->DefaultC.back, &Scr->SizeFont);
MyFont_DrawImageString (dpy, Scr->SizeWindow, &Scr->SizeFont,
diff --git a/src/session.c b/src/session.c
index 7c4ce99..87af4e1 100644
--- a/src/session.c
+++ b/src/session.c
@@ -741,12 +741,11 @@ int *pFd;
char tempFile[PATH_MAX];
char *tmp;
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
+ snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix);
tmp = (char *) mktemp (tempFile);
if (tmp)
{
- char *ptr = (char *) malloc (strlen (tmp) + 1);
- strcpy (ptr, tmp);
+ char *ptr = strdup(tmp);
return (ptr);
}
else
@@ -756,13 +755,8 @@ int *pFd;
char tempFile[PATH_MAX];
char *ptr;
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
- ptr = (char *)malloc(strlen(tempFile) + 1);
- if (ptr != NULL)
- {
- strcpy(ptr, tempFile);
- *pFd = mkstemp(ptr);
- }
+ snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix);
+ ptr = strdup(tempFile);
return ptr;
#endif
}
@@ -805,7 +799,7 @@ SmPointer clientData;
prop1val.value = Argv[0];
prop1val.length = strlen (Argv[0]);
- sprintf (userId, "%ld", (long)getuid());
+ snprintf (userId, sizeof(userId), "%ld", (long)getuid());
prop2.name = SmUserID;
prop2.type = SmARRAY8;
prop2.num_vals = 1;
@@ -924,7 +918,7 @@ SmPointer clientData;
prop1.num_vals = numVals;
- sprintf (discardCommand, "rm %s", filename);
+ snprintf (discardCommand, sizeof(discardCommand), "rm %s", filename);
prop2.name = SmDiscardCommand;
prop2.type = SmARRAY8;
prop2.num_vals = 1;
diff --git a/src/util.c b/src/util.c
index 1e87847..50675fd 100644
--- a/src/util.c
+++ b/src/util.c
@@ -265,14 +265,12 @@ ExpandFilename(char *name)
if (name[0] != '~') return name;
- newname = (char *) malloc (HomeLen + strlen(name) + 2);
+ asprintf(&newname, "%s/%s", Home, &name[1]);
if (!newname) {
fprintf (stderr,
"%s: unable to allocate %ld bytes to expand filename %s/%s\n",
ProgramName, HomeLen + (unsigned long)strlen(name) + 2,
Home, &name[1]);
- } else {
- (void) sprintf (newname, "%s/%s", Home, &name[1]);
}
return newname;
@@ -357,15 +355,13 @@ FindBitmap (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) {
fprintf (stderr,
"%s: unable to allocate memory for \"%s/%s\"\n",
ProgramName, 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) {
pm = None;
@@ -600,9 +596,9 @@ GetFont(MyFont *font)
XFreeFontSet(dpy, font->fontset);
}
- basename2 = (char *)malloc(strlen(font->name) + 3);
- if (basename2) sprintf(basename2, "%s,*", font->name);
- else basename2 = font->name;
+ asprintf(&basename2, "%s,*", font->name);
+ if (!basename2)
+ basename2 = font->name;
if( (font->fontset = XCreateFontSet(dpy, basename2,
&missing_charset_list_return,
&missing_charset_count_return,