[Mesa-dev] [PATCH] main: replace str*dup() by str*cpy() to be compliant with C89, C99.

Samuel Iglesias Gonsalvez siglesias at igalia.com
Mon Sep 28 01:09:57 PDT 2015


Fix SCons MinGW build error:

Compiling src/mesa/main/shader_query.cpp ...
src/mesa/main/shader_query.cpp: In function ‘char* get_top_level_name(const char*)’:
src/mesa/main/shader_query.cpp:841:34: error: ‘strndup’ was not declared in this scope
    return strndup(name, name_size);
                                  ^
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92124
Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
---
 src/mesa/main/shader_query.cpp | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index e020dce..7eecb39 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -838,18 +838,27 @@ get_top_level_name(const char *name)
    else
       name_size = first_square_bracket - name;
 
-   return strndup(name, name_size);
+   char *result = (char *) malloc((name_size + 1) * sizeof(char));
+   strncpy(result, name, name_size);
+   result[name_size] = '\0';
+   return result;
 }
 
 static char*
 get_var_name(const char *name)
 {
    const char *first_dot = strchr(name, '.');
+   char *result;
 
-   if (!first_dot)
-      return strdup(name);
-
-   return strndup(first_dot+1, strlen(first_dot) - 1);
+   if (!first_dot) {
+      result = (char *) malloc(strlen(name) * sizeof(char));
+      return strcpy(result, name);
+   }
+   int var_name_size = strlen(first_dot) - 1;
+   result = (char *) malloc((var_name_size + 1) * sizeof(char));
+   strncpy(result, first_dot+1, var_name_size);
+   result[var_name_size] = '\0';
+   return result;
 }
 
 static GLint
-- 
2.1.4



More information about the mesa-dev mailing list