Skip to content

Commit 05edad7

Browse files
committed
Revert "common/common.c: extend xbasename(), xstrdup() and xrealloc() definition to return NULL if input was NULL (and log it) [#2052]"
This reverts commit 05610d1. Seems to cause segfaults on its own, maybe something relied on older behavior (non-NULLs returned in case of bad inputs?) To investigate separately later...
1 parent d2857f6 commit 05edad7

1 file changed

Lines changed: 5 additions & 29 deletions

File tree

common/common.c

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -643,21 +643,11 @@ int sendsignal(const char *progname, const char * sig)
643643

644644
const char *xbasename(const char *file)
645645
{
646-
const char *p;
647-
#ifdef WIN32
648-
const char *r;
649-
#endif
650-
651-
if (file == NULL) {
652-
upsdebugx(1, "%s: got null input", __func__);
653-
return NULL;
654-
}
655-
656646
#ifndef WIN32
657-
p = strrchr(file, '/');
647+
const char *p = strrchr(file, '/');
658648
#else
659-
p = strrchr(file, '\\');
660-
r = strrchr(file, '/');
649+
const char *p = strrchr(file, '\\');
650+
const char *r = strrchr(file, '/');
661651
/* if not found, try '/' */
662652
if( r > p ) {
663653
p = r;
@@ -1739,14 +1729,7 @@ void *xcalloc(size_t number, size_t size)
17391729

17401730
void *xrealloc(void *ptr, size_t size)
17411731
{
1742-
void *p;
1743-
1744-
if (ptr == NULL) {
1745-
upsdebugx(1, "%s: got null input", __func__);
1746-
return NULL;
1747-
}
1748-
1749-
p = realloc(ptr, size);
1732+
void *p = realloc(ptr, size);
17501733

17511734
if (p == NULL)
17521735
fatal_with_errno(EXIT_FAILURE, "%s", oom_msg);
@@ -1755,14 +1738,7 @@ void *xrealloc(void *ptr, size_t size)
17551738

17561739
char *xstrdup(const char *string)
17571740
{
1758-
char *p;
1759-
1760-
if (string == NULL) {
1761-
upsdebugx(1, "%s: got null input", __func__);
1762-
return NULL;
1763-
}
1764-
1765-
p = strdup(string);
1741+
char *p = strdup(string);
17661742

17671743
if (p == NULL)
17681744
fatal_with_errno(EXIT_FAILURE, "%s", oom_msg);

0 commit comments

Comments
 (0)