[PATCH 4/5] kinput: allocate enough space for null character.
jeremyhu at apple.com
Wed Oct 19 16:50:49 PDT 2011
>> tam_key = (strchr(string, '=') - string);
>> - newopt->key = (char *)malloc(tam_key);
>> + newopt->key = (char *)malloc(tam_key + 1);
>> strncpy(newopt->key, string, tam_key);
>> newopt->key[tam_key] = '\0';
>> newopt->value = strdup(strchr(string, '=') + 1);
> Is strndup() portable enough to be used here? I don't see any other
> instances yet in the xserver git master or any of the other X.Org
> trees I have checked out.
> It's not in our traditional Unix98 baseline, but
> says it's in the 2008 version of POSIX.
I added strndup to Apple's Libc during Lion development, so it is there for most recent release, but not previous releases. There are a non-trivial number of users who want to build X11 bits on older versions of the OS, and I'd rather not provide an in-project implementation of strndup just for these users of kdrive.
That being said, I wouldn't be opposed to bumping our baseline from Unix98 to something more modern, but SUSv4 doesn't even have a test suite yet, so I'd prefer picking SUSv3 as that target.
More information about the xorg-devel