aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/basename.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/toys/posix/basename.c b/toys/posix/basename.c
index c49a5f36..1a27a23b 100644
--- a/toys/posix/basename.c
+++ b/toys/posix/basename.c
@@ -24,8 +24,10 @@ void basename_main(void)
// chop off the suffix if provided
if (suffix) {
- char *s = base + strlen(base) - strlen(suffix);
- if (s > base && !strcmp(s, suffix)) *s = 0;
+ long bl = strlen(base), sl = strlen(suffix);
+ char *s = base + bl - sl;
+
+ if (bl > sl && !strcmp(s, suffix)) *s = 0;
}
puts(base);