[RFC/PATCH v3 6/8] libbb: add is_suffixed_with() function

Bartosz Gołaszewski bartekgola at gmail.com
Tue Aug 25 18:16:56 UTC 2015


2015-08-25 19:29 GMT+02:00 Xabier Oneca  --  xOneca <xoneca at gmail.com>:
> Hello Bartosz,
>
> 2015-08-25 13:10 GMT+02:00 Bartosz Golaszewski <bartekgola at gmail.com>:
>> +/*
>> + * Return NULL if string is not suffixed with key. Return pointer to the
>> + * beginning of prefix key in string. If key is an empty string return pointer
>> + * to the end of string.
>> + */
>> +char* FAST_FUNC is_suffixed_with(const char *string, const char *key)
>> +{
>> +       size_t str_len = strlen(string), key_len = strlen(key);
>> +
>> +       if (str_len >= key_len) {
>> +               if (strcmp(string + str_len - key_len, key) == 0) {
>> +                       return (char*)key;
>> +               }
>> +       }
>> +
>> +       return NULL;
>> +}
>
> Sorry to bug you again with this function, and I know it is too late,
> but it doesn't do what the comment before the function says it does.
>
> It says it returns a pointer to the beginning of prefix key *in
> string*, but what returns is a pointer to *key*. It's a subtle change,
> but as it is now the return value may not be as useful... (it's like
> returning 1/0 but with key/NULL.)
>
> Cheers,
>
> Xabier Oneca_,,_

You're right, I missed that one. Will send a patch tomorrow.

-- 
Best regards,
Bartosz Golaszewski


More information about the busybox mailing list