Fix some bugs in the new mpw_strings & mpw_strncasecmp.
This commit is contained in:
parent
b5040a7786
commit
42d78da74e
@ -67,17 +67,19 @@ const char **mpw_strings(size_t *count, const char *strings, ...) {
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, strings );
|
va_start( args, strings );
|
||||||
const char **array = NULL;
|
const char **array = NULL;
|
||||||
size_t arraySize = 0;
|
size_t size = 0;
|
||||||
for (const char *string; (string = va_arg( args, const char * ));) {
|
for (const char *string = strings; string; (string = va_arg( args, const char * ))) {
|
||||||
size_t cursor = arraySize;
|
size_t cursor = size / sizeof( *array );
|
||||||
if (!mpw_realloc( &array, &arraySize, sizeof(string) )) {
|
if (!mpw_realloc( &array, &size, sizeof( string ) )) {
|
||||||
mpw_free( &array, arraySize );
|
mpw_free( &array, size );
|
||||||
|
*count = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
array[cursor] = string;
|
array[cursor] = string;
|
||||||
}
|
}
|
||||||
va_end( args );
|
va_end( args );
|
||||||
|
|
||||||
|
*count = size / sizeof( *array );
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,12 +520,9 @@ char *mpw_strndup(const char *src, size_t max) {
|
|||||||
|
|
||||||
int mpw_strncasecmp(const char *s1, const char *s2, size_t max) {
|
int mpw_strncasecmp(const char *s1, const char *s2, size_t max) {
|
||||||
|
|
||||||
if (s1 && s2 && max)
|
int cmp = 0;
|
||||||
for (; --max > 0; ++s1, ++s2) {
|
for (; !cmp && max-- > 0 && s1 && s2; ++s1, ++s2)
|
||||||
int cmp = tolower( *(unsigned char *)s1 ) - tolower( *(unsigned char *)s2 );
|
cmp = tolower( *(unsigned char *)s1 ) - tolower( *(unsigned char *)s2 );
|
||||||
if (!cmp || *s1 == '\0')
|
|
||||||
return cmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,9 @@ bool mpw_push_int(
|
|||||||
/** Reallocate the given buffer from the given size by adding the delta size.
|
/** Reallocate the given buffer from the given size by adding the delta size.
|
||||||
* On success, the buffer size pointer will be updated to the buffer's new size
|
* On success, the buffer size pointer will be updated to the buffer's new size
|
||||||
* and the buffer pointer may be updated to a new memory address.
|
* and the buffer pointer may be updated to a new memory address.
|
||||||
* On failure, the buffer and pointers will remain unaffected.
|
* On failure, the pointers will remain unaffected.
|
||||||
* @param buffer A pointer to the buffer to reallocate.
|
* @param buffer A pointer to the buffer to reallocate.
|
||||||
* @param bufferSize A pointer to the buffer's actual size.
|
* @param bufferSize A pointer to the buffer's current size.
|
||||||
* @param deltaSize The amount to increase the buffer's size by.
|
* @param deltaSize The amount to increase the buffer's size by.
|
||||||
* @return true if successful, false if reallocation failed.
|
* @return true if successful, false if reallocation failed.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user