[PATCH 5/7] xf86ShowOpts.c: Remove bad code from DoShowOptions

Alan Coopersmith alan.coopersmith at oracle.com
Tue Nov 1 15:42:20 PDT 2011


When we want to print a string, it's okay to just print it.
We don't need to first allocate a buffer 2 bytes bigger than the
string, copy the entire string unmodified to the buffer, print the
buffer, and then leak the buffer (though we AbortDDX 8 lines later,
and then just in case we survived that, call exit as well, so the
leak is short lived, just oh so pointless).

Oh, and for good measure, put the "r" in String, no matter how
much it stings.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 hw/xfree86/common/xf86ShowOpts.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c
index a805916..3c3f615 100644
--- a/hw/xfree86/common/xf86ShowOpts.c
+++ b/hw/xfree86/common/xf86ShowOpts.c
@@ -53,7 +53,7 @@
 #include "globals.h"
 
 static const char* 
-optionTypeToSting(OptionValueType type)
+optionTypeToString(OptionValueType type)
 {
     switch (type) {
     case OPTV_NONE:
@@ -107,16 +107,8 @@ void DoShowOptions (void) {
 					i,xf86DriverList[i]->driverName,vers->vendor
 				);
 				for (p = pOption; p->name != NULL; p++) {
-					const char *opttype = optionTypeToSting(p->type);
-					/* XXX: Why overallocate by 2 bytes?
-					 * Otherwise, this would be strdup()
-					 */
-					char *optname = malloc(strlen(p->name) + 2 + 1);
-					if (!optname) {
-						continue;                      
-					}
-					sprintf(optname, "%s", p->name);
-					ErrorF ("\t%s:%s\n", optname,opttype);
+					ErrorF ("\t%s:%s\n", p->name,
+						optionTypeToString(p->type));
 				}
 				ErrorF ("}\n");
 			}
-- 
1.7.3.2



More information about the xorg-devel mailing list