|
@@ -104,7 +104,7 @@ static int set_string(dbString * x, char *s, int copy)
|
|
|
else {
|
|
|
db_free_string(x);
|
|
|
x->string = s;
|
|
|
- x->nalloc = -1; /* fixme */
|
|
|
+ x->nalloc = -1;
|
|
|
}
|
|
|
return DB_OK;
|
|
|
}
|
|
@@ -120,14 +120,9 @@ static int set_string(dbString * x, char *s, int copy)
|
|
|
*/
|
|
|
int db_enlarge_string(dbString * x, int len)
|
|
|
{
|
|
|
- if (x->nalloc <= 0) {
|
|
|
- x->string = db_malloc(len * sizeof(char));
|
|
|
- if (x->string == NULL)
|
|
|
- return DB_MEMORY_ERR;
|
|
|
- x->nalloc = len;
|
|
|
- strcpy(x->string, "");
|
|
|
- }
|
|
|
- else if (x->nalloc < len) {
|
|
|
+ if (x->nalloc < len) {
|
|
|
+ if (x->nalloc < 0)
|
|
|
+ x->string = NULL;
|
|
|
x->string = db_realloc((void *)x->string, len);
|
|
|
if (x->string == NULL)
|
|
|
return DB_MEMORY_ERR;
|
|
@@ -155,7 +150,7 @@ char *db_get_string(const dbString * x)
|
|
|
*/
|
|
|
void db_free_string(dbString * x)
|
|
|
{
|
|
|
- if (x->nalloc != 0)
|
|
|
+ if (x->nalloc > 0)
|
|
|
db_free(x->string);
|
|
|
db_init_string(x);
|
|
|
}
|
|
@@ -213,10 +208,10 @@ int db_append_string(dbString * x, const char *s)
|
|
|
int len;
|
|
|
int stat;
|
|
|
|
|
|
- if (db_get_string(x))
|
|
|
- len = strlen(db_get_string(x)) + strlen(s) + 1;
|
|
|
- else
|
|
|
- len = strlen(s) + 1;
|
|
|
+ if (!db_get_string(x))
|
|
|
+ return db_set_string(x, s);
|
|
|
+
|
|
|
+ len = strlen(db_get_string(x)) + strlen(s) + 1;
|
|
|
stat = db_enlarge_string(x, len);
|
|
|
if (stat != DB_OK)
|
|
|
return stat;
|