I noticed a gcc warning on cmd_string_uppercase() and ended up almost rewriting it, since I disliked the extra copy by cmd_string.

Also note that the if (!ret || q == NULL) was useless, since cmd_string always returns true, and q would never be NULL (it would have crashed inside xstrdup, see gnulib/lib/xmalloc.c).

Regards

commit 98d101673c4753a758cd56681a0f85bcf5c37a32
Author: Ángel González <[email protected]>
Date:   Fri Jun 21 23:58:37 2013 +0200

    Cleanup cmd_string_uppercase()

diff --git a/src/init.c b/src/init.c
index 54a2919..c390a60 100644
--- a/src/init.c
+++ b/src/init.c
@@ -965,15 +965,16 @@ cmd_string (const char *com, const char *val, void *place)
 static bool
 cmd_string_uppercase (const char *com, const char *val, void *place)
 {
-  char *q;
-  bool ret = cmd_string (com, val, place);
-  q = *((char **) place);
-  if (!ret || q == NULL)
-    return false;
+  char *q, **pstring;
+  pstring = (char **)place;
+  xfree_null (*pstring);
+
+  *pstring = xmalloc(strlen(val) + 1);
 
-  for ( ;*q; *q++)
-    *q = c_toupper (*q);
+  for (q = *pstring; *val; val++, q++)
+    *q = c_toupper (*val);
 
+  *q = '\0';
   return true;
 }
 

Reply via email to