Another garnome on Solaris x86 issue - scrollkeeper bug



An additional problem - scrollkeeper uses the completely non-standard strndup() function in libs/i18n.c. Folks seem to assume everyone runs Linux - ah well. The following patch should be equivalent, if I read the strndup man page correctly. The patch assumes strlcpy() is available - it really should be a configure test, or use strncpy() and explicitly null terminate, but I'm feeling lazy. And yes, I may return NULL pointers, but only if the original code would. Blech - I feel slimy...

--- i18n.c.DIST 2003-09-28 19:52:29.573124000 -0400
+++ i18n.c      2003-09-28 19:55:08.190046000 -0400
@@ -62,7 +62,10 @@

       if (dot_pos) {
               mask |= CODESET;
-               *codeset = strndup(dot_pos, at_pos - dot_pos);
+               *codeset = malloc((at_pos - dot_pos) + 1);
+               if (*codeset != NULL) {
+                   strlcpy(*codeset, dot_pos, ((at_pos - dot_pos) + 1));
+               }
       } else {
               dot_pos = at_pos;
               *codeset = strdup("");
@@ -70,13 +73,19 @@

       if (uscore_pos) {
               mask |= TERRITORY;
-               *territory = strndup(uscore_pos, dot_pos - uscore_pos);
+               *territory = malloc((dot_pos - uscore_pos) + 1);
+               if (*territory != NULL) {
+ strlcpy(*territory, uscore_pos, ((dot_pos - uscore_pos) + 1));
+               }
       } else {
               uscore_pos = dot_pos;
               *territory = strdup("");
       }

-       *language = strndup(locale, uscore_pos - locale);
+       *language = malloc((uscore_pos - locale) + 1);
+       if (*language != NULL) {
+               strlcpy(*language, locale, ((uscore_pos - locale) + 1));
+       }

       return mask;
}




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