[hackers] [sbase] Fix comparison >= 0 is always true in basename(1) || sin
commit 1059782af84c435899826436898dd2c2f48a0978
Author: sin <sin_AT_2f30.org>
Date: Mon Dec 8 12:14:13 2014 +0000
Fix comparison >= 0 is always true in basename(1)
diff --git a/basename.c b/basename.c
index cbfaf70..5acd63d 100644
--- a/basename.c
+++ b/basename.c
_AT_@ -17,8 +17,8 @@ usage(void)
int
main(int argc, char *argv[])
{
- char *s, *p;
- size_t d;
+ char *p;
+ size_t off;
ARGBEGIN {
default:
_AT_@ -28,15 +28,14 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
- s = strlen(argv[0]) ? basename(argv[0]) : ".";
- if (argc == 2 && *s != '/') {
- d = strlen(s) - strlen(argv[1]);
- if (d >= 0) {
- p = s + d;
- if (strcmp(p, argv[1]) == 0)
- *p = '\0';
+ p = strlen(argv[0]) ? basename(argv[0]) : ".";
+ if (argc == 2 && *p != '/') {
+ if (strlen(argv[1]) < strlen(p)) {
+ off = strlen(p) - strlen(argv[1]);
+ if (strcmp(&p[off], argv[1]) == 0)
+ p[off] = '\0';
}
}
- puts(s);
+ puts(p);
return 0;
}
Received on Mon Dec 08 2014 - 13:14:48 CET
This archive was generated by hypermail 2.3.0
: Mon Dec 08 2014 - 13:24:09 CET