commit 7eb5eb7f5d9fdf3a7220632f9bac4bbfdc85a4a3
parent 14440bc620b6034cdac57357fba02dad435a1929
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Mon, 29 May 2006 12:48:21 +0200
fixed the issue reported by tkoskine with sscanf
Diffstat:
5 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/cmd/wm/area.c b/cmd/wm/area.c
@@ -5,7 +5,6 @@
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include "wm.h"
@@ -124,8 +123,7 @@ select_area(Area *a, char *arg)
return;
}
else {
- i = strtol(arg, nil, 10);
- if(errno)
+ if(sscanf(arg, "%d", &i) != 1)
return;
}
new = v->area.data[i];
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -5,7 +5,6 @@
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include <X11/Xatom.h>
#include "wm.h"
@@ -616,8 +615,7 @@ select_client(Client *c, char *arg)
i = 0;
}
else {
- i = strtol(arg, nil, 10);
- if(errno)
+ if(sscanf(arg, "%d", &i) != 1)
return;
}
focus_client(a->frame.data[i]->client, True);
@@ -741,8 +739,7 @@ send_client(Client *c, char *arg)
focus_client(c, True);
}
else if(i) {
- j = strtol(arg, nil, 10);
- if(errno)
+ if(sscanf(arg, "%d", &j) != 1)
return;
to = v->area.data[j];
send_to_area(to, a, c);
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -3,7 +3,6 @@
* See LICENSE file for license details.
*/
-#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -72,7 +71,6 @@ enum { WMII_IOUNIT = 2048 };
*/
Qid root_qid;
-static const char *errstr;
/* IXP stuff */
@@ -326,8 +324,7 @@ type_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
return FsDview;
if(!strncmp(name, "sel", 4))
goto dyndir;
- i = (unsigned short) strtol(name, nil, 10);
- if(errno)
+ if(sscanf(name, "%d", &i) != 1)
return FsLast;
dyndir:
switch(dir_type) {
@@ -386,8 +383,9 @@ qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
new.path = pack_qpath(FsDarea, p->id, p->area.data[p->sel]->id, 0);
}
else {
- i = strtol(name, nil, 10);
- if(errno || (i >= p->area.size))
+ if(sscanf(name, "%d", &i) != 1)
+ return nil;
+ if(i >= p->area.size)
return nil;
new.path = pack_qpath(FsDarea, p->id, p->area.data[i]->id, 0);
}
@@ -406,8 +404,9 @@ qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
new.path = pack_qpath(FsDclient, p->id, a->id, a->frame.data[a->sel]->id);
}
else {
- i = strtol(name, nil, 10);
- if(errstr || (i >= a->frame.size))
+ if(sscanf(name, "%d", &i) != 1)
+ return nil;
+ if(i >= a->frame.size)
return nil;
new.path = pack_qpath(FsDclient, p->id, a->id, a->frame.data[i]->id);
}
@@ -416,8 +415,9 @@ qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
case FsDGclient:
if(dir_type != FsDclients)
return nil;
- i = strtol(name, nil, 10);
- if(errno || (i >= client.size))
+ if(sscanf(name, "%d", &i) != 1)
+ return nil;
+ if(i >= client.size)
return nil;
new.path = pack_qpath(FsDGclient, client.data[i]->id, 0, 0);
break;
@@ -1358,8 +1358,9 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
- i = strtol(buf, nil, 10);
- if(errno)
+ if(sscanf(buf, "%d", &i) != 1)
+ return Ebadvalue;
+ if(i < 0 || i > 100)
return Ebadvalue;
def.border = i;
resize_all_clients();
@@ -1485,8 +1486,9 @@ xwrite(IXPConn *c, Fcall *fcall)
return Ebadvalue;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
- i = strtol(buf, nil, 10);
- if(errno || (i && i < MIN_COLWIDTH))
+ if(sscanf(buf, "%d", &i) != 1)
+ return Ebadvalue;
+ if(i && i < MIN_COLWIDTH)
return Ebadvalue;
def.colw = i;
break;
diff --git a/cmd/wmiiwarp.c b/cmd/wmiiwarp.c
@@ -38,11 +38,9 @@ main(int argc, char **argv)
fprintf(stderr, "%s", "wmiiwarp: cannot open display\n");
exit(1);
}
- x = strtol(argv[1], nil, 10);
- if(errno)
+ if(sscanf(argv[1], "%d", &x) != 1)
usage();
- y = strtol(argv[2], nil, 10);
- if(errno)
+ if(sscanf(argv[1], "%d", &y) != 1)
usage();
XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 0, 0, x, y);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
diff --git a/libixp/socket.c b/libixp/socket.c
@@ -14,7 +14,6 @@
#include <netdb.h>
#include <sys/un.h>
#include <unistd.h>
-#include <errno.h>
#include "ixp.h"
@@ -52,9 +51,7 @@ connect_inet_sock(char *host)
return -1;
*port = 0;
port++;
- prt = strtol(port, nil, 10);
-
- if(errno)
+ if(sscanf(port, "%d", &prt) != 1)
return -1;
/* init */
@@ -117,8 +114,7 @@ create_inet_sock(char *host, char **errstr)
}
*port = 0;
port++;
- prt = strtol(port, nil, 10);
- if(errno) {
+ if(sscanf(port, "%d", &prt) != 1) {
*errstr = "invalid port number";
return -1;
}