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