Bugs fixed

This commit is contained in:
Juan Ferrer 2019-12-02 19:37:19 +01:00
parent e550ef0b6d
commit 7cd78a8eeb
1 changed files with 8 additions and 5 deletions

View File

@ -2,7 +2,7 @@
// Value handling functions
#define INT(ptr) (*((long long *) ptr))
#define DOUBLE(ptr) (*((double *) ptr))
#define REAL(ptr) (*((double *) ptr))
#define min(a,b) (a < b ? a : b)
typedef union {
@ -27,7 +27,10 @@ void value_init(Value * value) {
}
void value_free_val(Value *value) {
if (value->free) free(value->val.s);
if (value->free) {
free(value->val.s);
value->free = 0;
}
}
void value_set_null(Value *value) {
@ -37,7 +40,6 @@ void value_set_null(Value *value) {
void value_set(Value * value, UDF_ARGS *args, int arg_index, int copy) {
char * arg = args->args[arg_index];
value->free = 0;
if (arg != NULL) {
value->is_null = 0;
@ -48,12 +50,12 @@ void value_set(Value * value, UDF_ARGS *args, int arg_index, int copy) {
value->val.i = INT(arg);
break;
case REAL_RESULT:
value->val.d = DOUBLE(arg);
value->val.d = REAL(arg);
break;
default:
value->free = copy;
value->len = args->lengths[arg_index];
if (copy) {
value->free = 1;
value->val.s = (char *) malloc(value->len);
memcpy(value->val.s, arg, value->len);
} else
@ -64,6 +66,7 @@ void value_set(Value * value, UDF_ARGS *args, int arg_index, int copy) {
}
void value_from_arg(Value * value, UDF_ARGS *args, int arg_index) {
value->free = 0;
value_set(value, args, arg_index, 0);
}