[GRASS-SVN] r50379 - grass/trunk/lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 22 03:30:59 EST 2012
Author: mmetz
Date: 2012-01-22 00:30:59 -0800 (Sun, 22 Jan 2012)
New Revision: 50379
Modified:
grass/trunk/lib/db/dbmi_base/string.c
Log:
fix r50370
Modified: grass/trunk/lib/db/dbmi_base/string.c
===================================================================
--- grass/trunk/lib/db/dbmi_base/string.c 2012-01-22 08:28:19 UTC (rev 50378)
+++ grass/trunk/lib/db/dbmi_base/string.c 2012-01-22 08:30:59 UTC (rev 50379)
@@ -104,7 +104,7 @@
else {
db_free_string(x);
x->string = s;
- x->nalloc = -1; /* fixme */
+ x->nalloc = -1;
}
return DB_OK;
}
@@ -120,14 +120,9 @@
*/
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 @@
*/
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 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;
More information about the grass-commit
mailing list