]> git.armaanb.net Git - sic.git/blobdiff - util.c
util: trim() fix for UB on pointer arithmetic
[sic.git] / util.c
diff --git a/util.c b/util.c
index cb966d43c89ae24bae1afcdf32e7136f8ef68367..8cea8836cf6dc14dbadb5394201b45cda9dc0d34 100644 (file)
--- a/util.c
+++ b/util.c
@@ -60,8 +60,7 @@ static void
 trim(char *s) {
        char *e;
 
-       e = s + strlen(s) - 1;
-       while(e > s && isspace((unsigned char)*e))
-               e--;
-       *(e + 1) = '\0';
+       for (e = s + strlen(s); e > s && isspace((unsigned char)*(e - 1)); e--)
+               ;
+       *e = '\0';
 }