Changes for 3.3.1dev.
[rsync.git] / util2.c
diff --git a/util2.c b/util2.c
index 8879c987afa0888fbd008a9eb28863c558f95954..b59bff0a0b541b8f6837f6d87938ced8e5bac9b9 100644 (file)
--- a/util2.c
+++ b/util2.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2020 Wayne Davison
+ * Copyright (C) 2003-2024 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 
 extern size_t max_alloc;
 
-char *do_malloc = "42";
+char *do_calloc = "42";
 
 /**
  * Sleep for a specified number of milliseconds.
@@ -72,7 +72,7 @@ int msleep(int t)
 
 void *my_alloc(void *ptr, size_t num, size_t size, const char *file, int line)
 {
-       if (max_alloc && num >= max_alloc/size) {
+       if (num >= max_alloc/size) {
                if (!file)
                        return NULL;
                rprintf(FERROR, "[%s] exceeded --max-alloc=%s setting (file=%s, line=%d)\n",
@@ -80,9 +80,9 @@ void *my_alloc(void *ptr, size_t num, size_t size, const char *file, int line)
                exit_cleanup(RERR_MALLOC);
        }
        if (!ptr)
-               ptr = calloc(num, size);
-       else if (ptr == do_malloc)
                ptr = malloc(num * size);
+       else if (ptr == do_calloc)
+               ptr = calloc(num, size);
        else
                ptr = realloc(ptr, num * size);
        if (!ptr && file)
@@ -135,11 +135,8 @@ const char *src_file(const char *file)
        static int prefix = -1;
 
        if (prefix < 0) {
-               const char *cp;
-               for (cp = util2, prefix = 0; *cp; cp++) {
-                       if (*cp == '/')
-                               prefix = cp - util2 + 1;
-               }
+               const char *cp = strrchr(util2, '/');
+               prefix = cp ? cp - util2 + 1 : 0;
        }
 
        if (prefix && strncmp(file, util2, prefix) == 0)