util: Fix off-by-one error in message about overflow
authorMartin Schwenke <martin@meltin.net>
Mon, 1 Jul 2019 11:42:56 +0000 (21:42 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 5 Jul 2019 02:24:52 +0000 (02:24 +0000)
len includes space for the NUL character, so the calculation needs to
take the NUL character into account.

While touching this, drop unnecessary casts by updating format string
and update to modern debug macro.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Jul  5 02:24:52 UTC 2019 on sn-devel-184

lib/util/substitute.c

index 0ddab17958847143d630939dc1921b151aa48982..2d88e97fd19a9e33f91cee6b56dabf6294fe87c2 100644 (file)
@@ -66,10 +66,11 @@ static void string_sub2(char *s,const char *pattern, const char *insert, size_t
 
        while (lp <= ls && (p = strstr_m(s,pattern))) {
                if (ls + li - lp >= len) {
-                       DEBUG(0,("ERROR: string overflow by "
-                               "%d in string_sub(%.50s, %d)\n",
-                                (int)(ls + li - lp - len),
-                                pattern, (int)len));
+                       DBG_ERR("ERROR: string overflow by "
+                               "%zu in string_sub(%.50s, %zu)\n",
+                               ls + li - lp + 1 - len,
+                               pattern,
+                               len);
                        break;
                }
                if (li != lp) {
@@ -193,10 +194,11 @@ _PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, siz
 
        while (lp <= ls && (p = strstr_m(s,pattern))) {
                if (ls + li - lp >= len) {
-                       DEBUG(0,("ERROR: string overflow by "
-                               "%d in all_string_sub(%.50s, %d)\n",
-                                (int)(ls + li - lp - len),
-                                pattern, (int)len));
+                       DBG_ERR("ERROR: string overflow by "
+                               "%zu in all_string_sub(%.50s, %zu)\n",
+                               ls + li - lp + 1 - len,
+                               pattern,
+                               len);
                        break;
                }
                if (li != lp) {