X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fxtypes-basic.c;h=fdb4f339ad9e7e749006ff934722edefeb037a32;hb=9c43db5f35819ce787a79915aacb1840a98fdff4;hp=ac8727d0cddc83ede99899a8cc2663f278221e31;hpb=f46cd54513203eb5ceb36831b379691fbca9189a;p=libucw.git diff --git a/ucw/xtypes-basic.c b/ucw/xtypes-basic.c index ac8727d0..fdb4f339 100644 --- a/ucw/xtypes-basic.c +++ b/ucw/xtypes-basic.c @@ -2,6 +2,7 @@ * UCW Library -- Basic Extended Types * * (c) 2014 Martin Mares + * (c) 2014 Robert Kessl * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -52,7 +53,6 @@ static const char *xt_double_format(void *src, u32 fmt, struct mempool *pool) return mp_printf(pool, "%.10lf", *(double *)src); case XTYPE_FMT_PRETTY: return mp_printf(pool, "%.2lf", *(double *)src); - case XTYPE_FMT_DEFAULT: default: return mp_printf(pool, "%.5lf", *(double *)src); @@ -65,7 +65,7 @@ static const char *xt_double_parse(const char *str, void *dest, struct mempool * size_t sz = strlen(str); errno = 0; double result = strtod(str, &endptr); - if(endptr != str + sz) return "Could not parse double."; + if(endptr != str + sz) return "Could not parse double"; if(errno == ERANGE) return "Could not parse double: overflow happend during parsing"; *((double *) dest) = result; @@ -82,7 +82,7 @@ const struct xtype xt_double = { /* bool */ -static const char *xt_bool_format(void *src, u32 fmt UNUSED, struct mempool *pool) // (struct table *tbl, int col, enum xtype_fmt fmt, bool val) +static const char *xt_bool_format(void *src, u32 fmt UNUSED, struct mempool *pool) { switch(fmt) { case XTYPE_FMT_DEFAULT: @@ -97,7 +97,7 @@ static const char *xt_bool_format(void *src, u32 fmt UNUSED, struct mempool *poo static const char *xt_bool_parse(const char *str, void *dest, struct mempool *pool UNUSED) { - if(str[1] == 0) { + if(str[1] == 0) { // FIXME: Possible segfault if(str[0] == '1') { *((bool *)dest) = false; return NULL; @@ -118,7 +118,7 @@ static const char *xt_bool_parse(const char *str, void *dest, struct mempool *po return NULL; } - return "Could not parse bool."; + return "Could not parse bool"; } const struct xtype xt_bool = { @@ -132,7 +132,7 @@ const struct xtype xt_bool = { static const char *xt_str_format(void *src, u32 fmt UNUSED, struct mempool *pool) { - return mp_printf(pool, "%s", (const char *) src); + return mp_strdup(pool, (const char *) src); } static const char *xt_str_parse(const char *str, void *dest, struct mempool *pool UNUSED)