Fix some bugs in the new mpw_strings & mpw_strncasecmp.
This commit is contained in:
		@@ -67,17 +67,19 @@ const char **mpw_strings(size_t *count, const char *strings, ...) {
 | 
			
		||||
    va_list args;
 | 
			
		||||
    va_start( args, strings );
 | 
			
		||||
    const char **array = NULL;
 | 
			
		||||
    size_t arraySize = 0;
 | 
			
		||||
    for (const char *string; (string = va_arg( args, const char * ));) {
 | 
			
		||||
        size_t cursor = arraySize;
 | 
			
		||||
        if (!mpw_realloc( &array, &arraySize, sizeof(string) )) {
 | 
			
		||||
            mpw_free( &array, arraySize );
 | 
			
		||||
    size_t size = 0;
 | 
			
		||||
    for (const char *string = strings; string; (string = va_arg( args, const char * ))) {
 | 
			
		||||
        size_t cursor = size / sizeof( *array );
 | 
			
		||||
        if (!mpw_realloc( &array, &size, sizeof( string ) )) {
 | 
			
		||||
            mpw_free( &array, size );
 | 
			
		||||
            *count = 0;
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
        array[cursor] = string;
 | 
			
		||||
    }
 | 
			
		||||
    va_end( args );
 | 
			
		||||
 | 
			
		||||
    *count = size / sizeof( *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) {
 | 
			
		||||
 | 
			
		||||
    if (s1 && s2 && max)
 | 
			
		||||
        for (; --max > 0; ++s1, ++s2) {
 | 
			
		||||
            int cmp = tolower( *(unsigned char *)s1 ) - tolower( *(unsigned char *)s2 );
 | 
			
		||||
            if (!cmp || *s1 == '\0')
 | 
			
		||||
                return cmp;
 | 
			
		||||
        }
 | 
			
		||||
    int cmp = 0;
 | 
			
		||||
    for (; !cmp && max-- > 0 && s1 && s2; ++s1, ++s2)
 | 
			
		||||
        cmp = tolower( *(unsigned char *)s1 ) - tolower( *(unsigned char *)s2 );
 | 
			
		||||
 | 
			
		||||
    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.
 | 
			
		||||
  * 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.
 | 
			
		||||
  * 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 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.
 | 
			
		||||
  * @return true if successful, false if reallocation failed.
 | 
			
		||||
  */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user