s/strcpy/strncpy and fix somes unused variables

This commit is contained in:
Philippe Pepiot
2010-11-19 17:36:37 +01:00
parent 82b17ea02f
commit d75746bcf4
11 changed files with 52 additions and 29 deletions

View File

@@ -116,7 +116,7 @@ barwin_draw_text(BarWindow *bw, int x, int y, char *text)
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg); draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */ /* Draw text */
draw_text(bw->dr, x, y, bw->fg, 0, text); draw_text(bw->dr, x, y, bw->fg, text);
barwin_refresh(bw); barwin_refresh(bw);
@@ -136,7 +136,7 @@ barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_imag
draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg); draw_rectangle(bw->dr, x - 4, 0, textw(text) + 8, bw->geo.height, bw->bg);
/* Draw text */ /* Draw text */
draw_image_ofset_text(bw->dr, x, y, bw->fg, 0, text, x_image_ofset, y_image_ofset); draw_image_ofset_text(bw->dr, x, y, bw->fg, text, x_image_ofset, y_image_ofset);
barwin_refresh(bw); barwin_refresh(bw);

View File

@@ -1023,7 +1023,7 @@ client_set_rules(Client *c)
if(XGetWindowProperty(dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, False, if(XGetWindowProperty(dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, False,
XA_STRING, &rf, &f, &n, &il, &data) == Success && data) XA_STRING, &rf, &f, &n, &il, &data) == Success && data)
{ {
strcpy(wwrole, (char*)data); strncpy(wwrole, (char*)data, sizeof(wwrole));
XFree(data); XFree(data);
} }

View File

@@ -33,9 +33,9 @@
#include "wmfs.h" #include "wmfs.h"
void void
draw_text(Drawable d, int x, int y, char* fg, int pad, char *str) draw_text(Drawable d, int x, int y, char* fg, char *str)
{ {
draw_image_ofset_text(d, x, y, fg, pad, str, 0, 0); draw_image_ofset_text(d, x, y, fg, str, 0, 0);
} }
/** Draw a string in a Drawable /** Draw a string in a Drawable
@@ -47,22 +47,28 @@ draw_text(Drawable d, int x, int y, char* fg, int pad, char *str)
* \param str String that will be draw * \param str String that will be draw
*/ */
void void
draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, int x_image_ofset, int y_image_ofset) draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset)
{ {
XftColor xftcolor; XftColor xftcolor;
XftDraw *xftd; XftDraw *xftd;
(void)pad; #ifdef HAVE_IMLIB
char *ostr = NULL;
int i, ni, sw = 0;
ImageAttr im[128];
size_t textlen;
#else
(void)x_image_ofset;
(void)y_image_ofset;
#endif /* HAVE_IMLIB */
if(!str) if(!str)
return; return;
/* To draw image everywhere we can draw text */ /* To draw image everywhere we can draw text */
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
char *ostr = NULL;
int i, ni, sw = 0;
ImageAttr im[128];
ostr = xstrdup(str); ostr = xstrdup(str);
textlen = strlen(ostr);
if(strstr(str, "i[")) if(strstr(str, "i["))
{ {
@@ -92,7 +98,7 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, in
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
if(strstr(ostr, "i[")) if(strstr(ostr, "i["))
strcpy(str, ostr); strncpy(str, ostr, textlen);
IFREE(ostr); IFREE(ostr);
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */
@@ -195,16 +201,20 @@ ushort
textw(char *text) textw(char *text)
{ {
XGlyphInfo gl; XGlyphInfo gl;
#ifdef HAVE_IMLIB
char *ostr = NULL;
ImageAttr im[128];
size_t textlen;
#endif /* HAVE_IMLIB */
if(!text) if(!text)
return 0; return 0;
#ifdef HAVE_IMLIB
char *ostr = NULL;
ImageAttr im[128]; #ifdef HAVE_IMLIB
ostr = xstrdup(text); ostr = xstrdup(text);
textlen = strlen(ostr);
if(strstr(text, "i[")) if(strstr(text, "i["))
parse_image_block(im, text); parse_image_block(im, text);
@@ -214,7 +224,7 @@ textw(char *text)
#ifdef HAVE_IMLIB #ifdef HAVE_IMLIB
if(strstr(ostr, "i[")) if(strstr(ostr, "i["))
strcpy(text, ostr); strncpy(text, ostr, textlen);
IFREE(ostr); IFREE(ostr);
#endif /* HAVE_IMLIB */ #endif /* HAVE_IMLIB */

View File

@@ -156,7 +156,7 @@ launcher_execute(Launcher *launcher)
else else
{ {
tabhits = 1; tabhits = 1;
strcpy(tmpbuf, buf); strncpy(tmpbuf, buf, sizeof(tmpbuf));
} }
@@ -169,7 +169,7 @@ launcher_execute(Launcher *launcher)
if (complete) if (complete)
{ {
strcpy(buf, tmpbuf); strncpy(buf, tmpbuf, sizeof(buf));
strncat(buf, complete, sizeof(buf)); strncat(buf, complete, sizeof(buf));
found = True; found = True;
free(complete); free(complete);

View File

@@ -91,6 +91,8 @@ screen_get_geo(int s)
XFree(xsi); XFree(xsi);
} }
#else
(void)s;
#endif /* HAVE_XINERAMA */ #endif /* HAVE_XINERAMA */
return geo; return geo;

View File

@@ -158,11 +158,11 @@ statustext_normal(int sc, char *str)
/* Draw normal text without any blocks */ /* Draw normal text without any blocks */
draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(strwc) + sw), draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(strwc) + sw),
FHINFOBAR, infobar[sc].bar->fg, 0, strwc); FHINFOBAR, infobar[sc].bar->fg, strwc);
if(n) if(n)
{ {
strcpy(buf, strwc); strncpy(buf, strwc, sizeof(buf));
for(i = k = 0; i < (int)strlen(str); ++i, ++k) for(i = k = 0; i < (int)strlen(str); ++i, ++k)
if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\') if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\')
@@ -177,9 +177,9 @@ statustext_normal(int sc, char *str)
/* Draw text with its color */ /* Draw text with its color */
draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(&buf[k]) + sw), draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - (textw(&buf[k]) + sw),
FHINFOBAR, col, 0, &buf[k]); FHINFOBAR, col, &buf[k]);
strcpy(buf, strwc); strncpy(buf, strwc, sizeof(buf));
++i; ++i;
} }
} }
@@ -233,7 +233,7 @@ statustext_handle(int sc, char *str)
/* Draw located text with stored properties. */ /* Draw located text with stored properties. */
for(i = 0; i < ns; ++i) for(i = 0; i < ns; ++i)
draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, 0, s[i].text); draw_text(infobar[sc].bar->dr, s[i].x - sw, s[i].y, s[i].color, s[i].text);
barwin_refresh(infobar[sc].bar); barwin_refresh(infobar[sc].bar);

View File

@@ -625,11 +625,22 @@ void
uicb_tag_rename(uicb_t cmd) uicb_tag_rename(uicb_t cmd)
{ {
screen_get_sel(); screen_get_sel();
size_t len;
char *str;
if(!cmd || !strlen(cmd)) if(!cmd || !(len = strlen(cmd)))
return; return;
strcpy(tags[selscreen][seltag[selscreen]].name, cmd); str = tags[selscreen][seltag[selscreen]].name;
len = strlen(str);
/* TODO: if strlen(cmd) > len, the tag name
* will be truncated...
* We can't do a realloc because if the pointer change
* free() on paser will segfault.on free_conf()...
*/
strncpy(str, cmd, len);
infobar_update_taglist(selscreen); infobar_update_taglist(selscreen);
infobar_draw(selscreen); infobar_draw(selscreen);

View File

@@ -417,7 +417,7 @@ patht(char *path)
if(!path) if(!path)
return NULL; return NULL;
strcpy(ret, path); strncpy(ret, path, sizeof(ret));
if(strstr(path, "~/")) if(strstr(path, "~/"))
sprintf(ret, "%s/%s", getenv("HOME"), path + 2); sprintf(ret, "%s/%s", getenv("HOME"), path + 2);

View File

@@ -103,7 +103,7 @@ viwmfs(int argc, char **argv)
} }
} }
else else
strcpy(str, argv[2]); strncpy(str, argv[2], sizeof(str));
if(!strcmp(str, "help")) if(!strcmp(str, "help"))
{ {

View File

@@ -466,7 +466,7 @@ main(int argc, char **argv)
break; break;
case 'C': case 'C':
strcpy(conf.confpath, optarg); strncpy(conf.confpath, optarg, sizeof(conf.confpath));
break; break;
case 'c': case 'c':

View File

@@ -144,8 +144,8 @@ void barwin_refresh_color(BarWindow *bw);
void barwin_refresh(BarWindow *bw); void barwin_refresh(BarWindow *bw);
/* draw.c */ /* draw.c */
void draw_text(Drawable d, int x, int y, char* fg, int pad, char *str); void draw_text(Drawable d, int x, int y, char* fg, char *str);
void draw_image_ofset_text(Drawable d, int x, int y, char* fg, int pad, char *str, int x_image_ofset, int y_image_ofset); void draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset);
void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color);
void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data); void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data);