[PATCH libdrm 1/3] xf86drm: replace sprintf()+strdup() with asprintf()

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

 



Signed-off-by: Eric Engestrom <eric.engestrom@xxxxxxxxxx>
---
 xf86drm.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index 3a9d0ed2cc9b196ae7d1..b6e5d8cc1bb50ffe75a2 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2823,7 +2823,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
     struct stat sbuf;
     const char *name = drmGetMinorName(type);
     int len;
-    char dev_name[64], buf[64];
+    char *dev_name, buf[64];
     int maj, min;
 
     if (!name)
@@ -2848,20 +2848,22 @@ static char *drmGetMinorNameForFD(int fd, int type)
 
     while ((ent = readdir(sysdir))) {
         if (strncmp(ent->d_name, name, len) == 0) {
-            snprintf(dev_name, sizeof(dev_name), DRM_DIR_NAME "/%s",
-                 ent->d_name);
+            if (asprintf(&dev_name, DRM_DIR_NAME "/%s",
+                 ent->d_name) < 0) {
+                dev_name = NULL;
+            }
 
             closedir(sysdir);
-            return strdup(dev_name);
+            return dev_name;
         }
     }
     return NULL;
 #else
     struct stat sbuf;
-    char buf[PATH_MAX + 1];
+    char *buf;
     const char *dev_name;
     unsigned int maj, min;
-    int n, base;
+    int base;
 
     if (fstat(fd, &sbuf))
         return NULL;
@@ -2890,11 +2892,10 @@ static char *drmGetMinorNameForFD(int fd, int type)
     if (base < 0)
         return NULL;
 
-    n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min - base);
-    if (n == -1 || n >= sizeof(buf))
+    if (asprintf(&buf, dev_name, DRM_DIR_NAME, min - base) < 0)
         return NULL;
 
-    return strdup(buf);
+    return buf;
 #endif
 }
 
@@ -4119,10 +4120,10 @@ char *drmGetDeviceNameFromFd2(int fd)
     return strdup(path);
 #else
     struct stat      sbuf;
-    char             node[PATH_MAX + 1];
+    char            *node;
     const char      *dev_name;
     int              node_type;
-    int              maj, min, n, base;
+    int              maj, min, base;
 
     if (fstat(fd, &sbuf))
         return NULL;
@@ -4155,11 +4156,10 @@ char *drmGetDeviceNameFromFd2(int fd)
     if (base < 0)
         return NULL;
 
-    n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
-    if (n == -1 || n >= PATH_MAX)
+    if (asprintf(&node, dev_name, DRM_DIR_NAME, min - base) < 0)
       return NULL;
 
-    return strdup(node);
+    return node;
 #endif
 }
 
-- 
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux