* 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
extern size_t max_alloc;
-char *do_malloc = "42";
+char *do_calloc = "42";
/**
* Sleep for a specified number of milliseconds.
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",
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)
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)