--- a/src/mesa/drivers/dri/common/xmlconfig.c.orig 2015-02-06 16:09:52.000000000 -0800 +++ a/src/mesa/drivers/dri/common/xmlconfig.c 2015-02-11 11:32:32.000000000 -0800 @@ -105,6 +105,24 @@ static const char *__getProgramName () { # endif #endif +#undef strndup +#define strndup __xmlconfig_strndup +static char * +strndup(const char *str, size_t n) +{ + size_t len; + char *copy; + + for (len = 0; len < n && str[len]; len++) + continue; + + if ((copy = (char *)malloc(len + 1)) == NULL) + return (NULL); + memcpy(copy, str, len); + copy[len] = '\0'; + return (copy); +} + /** \brief Find an option in an option cache with the name as key */ static uint32_t findOption (const driOptionCache *cache, const char *name) { uint32_t len = strlen (name); --- a/src/util/ralloc.c 2015-12-28 00:25:30.000000000 -0800 +++ b/src/util/ralloc.c 2015-12-28 00:26:50.000000000 -0800 @@ -353,17 +353,17 @@ ralloc_strdup(const void *ctx, const cha char * ralloc_strndup(const void *ctx, const char *str, size_t max) { size_t n; char *ptr; if (unlikely(str == NULL)) return NULL; - n = strnlen(str, max); + for (n = 0; n < max && str[n]; n++); ptr = ralloc_array(ctx, char, n + 1); memcpy(ptr, str, n); ptr[n] = '\0'; return ptr; } /* helper routine for strcat/strncat - n is the exact amount to copy */ --- a/src/compiler/glsl/linker.cpp.orig 2016-05-08 16:23:12.000000000 -0700 +++ a/src/compiler/glsl/linker.cpp 2016-05-08 16:28:12.000000000 -0700 @@ -518,6 +518,24 @@ } /* anonymous namespace */ +#undef strndup +#define strndup __linker_strndup +static char * +strndup(const char *str, size_t n) +{ + size_t len; + char *copy; + + for (len = 0; len < n && str[len]; len++) + continue; + + if ((copy = (char *)malloc(len + 1)) == NULL) + return (NULL); + memcpy(copy, str, len); + copy[len] = '\0'; + return (copy); +} + void linker_error(gl_shader_program *prog, const char *fmt, ...) {