sna: Fix canonical mode name to correctly use asprintf
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 24 Oct 2013 12:05:16 +0000 (13:05 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 24 Oct 2013 12:05:16 +0000 (13:05 +0100)
Whoops. Only the kernel sprintf() accepts NULL as a valid target string,
not libc's.

Reported-by: Jay Little <jaylittle@jaylittle.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=70835
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/sna/sna_display.c

index 7fcade6..3c39305 100644 (file)
@@ -2095,27 +2095,16 @@ sna_output_panel_edid(xf86OutputPtr output, DisplayModePtr modes)
        return xf86ModesAdd(modes, m);
 }
 
-static int _canonical_mode_name(DisplayModePtr mode, char *str)
-{
-       return sprintf(str, "%dx%d%s",
-                      mode->HDisplay, mode->VDisplay,
-                      mode->Flags & V_INTERLACE ? "i" : "");
-}
-
 static char *canonical_mode_name(DisplayModePtr mode)
 {
-        char *str;
-        int len;
-
-        len = _canonical_mode_name(mode, NULL);
-        if (len < 0)
-                return NULL;
+       char *str;
 
-        str = malloc(len + 1);
-        if (str != NULL)
-                _canonical_mode_name(mode, str);
+       if (asprintf(&str, "%dx%d%s",
+                    mode->HDisplay, mode->VDisplay,
+                    mode->Flags & V_INTERLACE ? "i" : "") < 0)
+               return NULL;
 
-        return str;
+       return str;
 }
 
 static DisplayModePtr