simplify initial memory allocs by using realloc in all cases
This commit is contained in:
parent
d2ad20b4c7
commit
a2c9d2a82b
@ -10448,9 +10448,8 @@ int unacmaybefold_string_utf16(const char* in, size_t in_length,
|
||||
int i;
|
||||
|
||||
out_size = in_length > 0 ? in_length : 1024;
|
||||
if (*outp) {
|
||||
|
||||
out = *outp;
|
||||
/* +1 for null */
|
||||
out = realloc(out, out_size + 1);
|
||||
if(out == 0) {
|
||||
if(debug_level >= UNAC_DEBUG_LOW)
|
||||
@ -10458,15 +10457,7 @@ int unacmaybefold_string_utf16(const char* in, size_t in_length,
|
||||
/* *outp is still valid. Let the caller free it */
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* +1 for null */
|
||||
out = malloc(out_size + 1);
|
||||
if (out == 0) {
|
||||
if(debug_level >= UNAC_DEBUG_LOW)
|
||||
DEBUG("malloc %d bytes failed\n", out_size+1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
out_length = 0;
|
||||
|
||||
for(i = 0; i < in_length; i += 2) {
|
||||
@ -10623,9 +10614,8 @@ static int convert(const char* from, const char* to,
|
||||
u8tou16 = from_utf8 && to_utf16;
|
||||
|
||||
out_size = in_length > 0 ? in_length : 1024;
|
||||
if(*outp) {
|
||||
|
||||
out = *outp;
|
||||
/* +1 for null */
|
||||
out = realloc(out, out_size + 1);
|
||||
if(out == 0) {
|
||||
/* *outp still valid, no freeing */
|
||||
@ -10633,15 +10623,7 @@ static int convert(const char* from, const char* to,
|
||||
DEBUG("realloc %d bytes failed\n", out_size+1);
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
/* +1 for null */
|
||||
out = malloc(out_size + 1);
|
||||
if(out == 0) {
|
||||
if(debug_level >= UNAC_DEBUG_LOW)
|
||||
DEBUG("malloc %d bytes failed\n", out_size+1);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out_remain = out_size;
|
||||
out_base = out;
|
||||
|
||||
|
||||
26
unac/unac.c
26
unac/unac.c
@ -10448,9 +10448,8 @@ int unacmaybefold_string_utf16(const char* in, size_t in_length,
|
||||
int i;
|
||||
|
||||
out_size = in_length > 0 ? in_length : 1024;
|
||||
if (*outp) {
|
||||
|
||||
out = *outp;
|
||||
/* +1 for null */
|
||||
out = realloc(out, out_size + 1);
|
||||
if(out == 0) {
|
||||
if(debug_level >= UNAC_DEBUG_LOW)
|
||||
@ -10458,15 +10457,7 @@ int unacmaybefold_string_utf16(const char* in, size_t in_length,
|
||||
/* *outp is still valid. Let the caller free it */
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* +1 for null */
|
||||
out = malloc(out_size + 1);
|
||||
if (out == 0) {
|
||||
if(debug_level >= UNAC_DEBUG_LOW)
|
||||
DEBUG("malloc %d bytes failed\n", out_size+1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
out_length = 0;
|
||||
|
||||
for(i = 0; i < in_length; i += 2) {
|
||||
@ -10623,9 +10614,8 @@ static int convert(const char* from, const char* to,
|
||||
u8tou16 = from_utf8 && to_utf16;
|
||||
|
||||
out_size = in_length > 0 ? in_length : 1024;
|
||||
if(*outp) {
|
||||
|
||||
out = *outp;
|
||||
/* +1 for null */
|
||||
out = realloc(out, out_size + 1);
|
||||
if(out == 0) {
|
||||
/* *outp still valid, no freeing */
|
||||
@ -10633,15 +10623,7 @@ static int convert(const char* from, const char* to,
|
||||
DEBUG("realloc %d bytes failed\n", out_size+1);
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
/* +1 for null */
|
||||
out = malloc(out_size + 1);
|
||||
if(out == 0) {
|
||||
if(debug_level >= UNAC_DEBUG_LOW)
|
||||
DEBUG("malloc %d bytes failed\n", out_size+1);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
out_remain = out_size;
|
||||
out_base = out;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user