fixing sizeof stuff

master
arg@mig29 18 years ago
parent 26fbf124fa
commit 8c20e5dbd3
  1. 4
      draw.c
  2. 10
      main.c

@ -35,8 +35,8 @@ drawtext(const char *text, unsigned long col[ColLast]) {
return; return;
w = 0; w = 0;
olen = len = strlen(text); olen = len = strlen(text);
if(len >= sizeof(buf)) if(len >= sizeof buf)
len = sizeof(buf) - 1; len = sizeof buf - 1;
memcpy(buf, text, len); memcpy(buf, text, len);
buf[len] = 0; buf[len] = 0;
h = dc.font.ascent + dc.font.descent; h = dc.font.ascent + dc.font.descent;

@ -144,7 +144,7 @@ kpress(XKeyEvent * e) {
len = strlen(text); len = strlen(text);
buf[0] = 0; buf[0] = 0;
num = XLookupString(e, buf, sizeof(buf), &ksym, 0); num = XLookupString(e, buf, sizeof buf, &ksym, 0);
if(IsFunctionKey(ksym) || IsKeypadKey(ksym) if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym) || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|| IsPrivateKeypadKey(ksym)) || IsPrivateKeypadKey(ksym))
@ -181,7 +181,7 @@ kpress(XKeyEvent * e) {
case XK_Tab: case XK_Tab:
if(!sel) if(!sel)
return; return;
strncpy(text, sel->text, sizeof(text)); strncpy(text, sel->text, sizeof text);
match(text); match(text);
break; break;
case XK_Right: case XK_Right:
@ -221,9 +221,9 @@ kpress(XKeyEvent * e) {
if(num && !iscntrl((int) buf[0])) { if(num && !iscntrl((int) buf[0])) {
buf[num] = 0; buf[num] = 0;
if(len > 0) if(len > 0)
strncat(text, buf, sizeof(text)); strncat(text, buf, sizeof text);
else else
strncpy(text, buf, sizeof(text)); strncpy(text, buf, sizeof text);
match(text); match(text);
} }
} }
@ -238,7 +238,7 @@ readstdin(void) {
Item *i, *new; Item *i, *new;
i = 0; i = 0;
while(fgets(buf, sizeof(buf), stdin)) { while(fgets(buf, sizeof buf, stdin)) {
len = strlen(buf); len = strlen(buf);
if (buf[len - 1] == '\n') if (buf[len - 1] == '\n')
buf[len - 1] = 0; buf[len - 1] = 0;

Loading…
Cancel
Save