[PATCH v2 1/2] xfuncs: return NULL from xstrdup_wchar(NULL)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ahmad Fatoum <ahmad@xxxxxx>

strdup_wchar, strdup_char_to_wchar and xstrdup_wchar_to_char all return
NULL when passed a NULL pointer. It's thus misleading for the xfunc
version of them to trigger an enomem_panic in that case.

Fix this by passing along the NULL pointer unchanged.
xstrdup() already behaves exactly this way.

Signed-off-by: Ahmad Fatoum <ahmad@xxxxxx>
---
v1 -> v2:
  - new patch
---
 lib/xfuncs.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index ac67bf4f5584..d4beecddf5aa 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -146,8 +146,12 @@ EXPORT_SYMBOL(xasprintf);
 
 wchar_t *xstrdup_wchar(const wchar_t *s)
 {
-	wchar_t *p = strdup_wchar(s);
+	wchar_t *p;
 
+	if (!s)
+		return NULL;
+
+	p = strdup_wchar(s);
 	if (!p)
 		enomem_panic((wcslen(s) + 1) * sizeof(wchar_t));
 
@@ -157,8 +161,12 @@ EXPORT_SYMBOL(xstrdup_wchar);
 
 wchar_t *xstrdup_char_to_wchar(const char *s)
 {
-	wchar_t *p = strdup_char_to_wchar(s);
+	wchar_t *p;
 
+	if (!s)
+		return NULL;
+
+	p = strdup_char_to_wchar(s);
 	if (!p)
 		enomem_panic((strlen(s) + 1) * sizeof(wchar_t));
 
@@ -168,8 +176,12 @@ EXPORT_SYMBOL(xstrdup_char_to_wchar);
 
 char *xstrdup_wchar_to_char(const wchar_t *s)
 {
-	char *p = strdup_wchar_to_char(s);
+	char *p;
 
+	if (!s)
+		return NULL;
+
+	p = strdup_wchar_to_char(s);
 	if (!p)
 		enomem_panic((wcslen(s) + 1) * sizeof(wchar_t));
 
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux