From 42a711443a27a9ffaf4187719cc18ff4344e12c8 Mon Sep 17 00:00:00 2001 From: ivanpauno Date: Fri, 21 Jun 2019 10:57:08 -0300 Subject: [PATCH] Quoted int or float values are strings Signed-off-by: ivanpauno --- rcl_yaml_param_parser/src/parser.c | 56 +++++++++++++++++------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/rcl_yaml_param_parser/src/parser.c b/rcl_yaml_param_parser/src/parser.c index 48bc286442..704470055f 100644 --- a/rcl_yaml_param_parser/src/parser.c +++ b/rcl_yaml_param_parser/src/parser.c @@ -772,40 +772,48 @@ static void * get_value( } /// Check for int - errno = 0; - ival = strtol(value, &endptr, 0); - if ((0 == errno) && (NULL != endptr)) { - if ((NULL != endptr) && (endptr != value)) { - if (('\0' != *value) && ('\0' == *endptr)) { - *val_type = DATA_TYPE_INT64; - ret_val = allocator.zero_allocate(1U, sizeof(int64_t), allocator.state); - if (NULL == ret_val) { - return NULL; + if (style != YAML_SINGLE_QUOTED_SCALAR_STYLE && + style != YAML_DOUBLE_QUOTED_SCALAR_STYLE) + { + errno = 0; + ival = strtol(value, &endptr, 0); + if ((0 == errno) && (NULL != endptr)) { + if ((NULL != endptr) && (endptr != value)) { + if (('\0' != *value) && ('\0' == *endptr)) { + *val_type = DATA_TYPE_INT64; + ret_val = allocator.zero_allocate(1U, sizeof(int64_t), allocator.state); + if (NULL == ret_val) { + return NULL; + } + *((int64_t *)ret_val) = ival; + return ret_val; } - *((int64_t *)ret_val) = ival; - return ret_val; } } } /// Check for float - errno = 0; - endptr = NULL; - dval = strtod(value, &endptr); - if ((0 == errno) && (NULL != endptr)) { - if ((NULL != endptr) && (endptr != value)) { - if (('\0' != *value) && ('\0' == *endptr)) { - *val_type = DATA_TYPE_DOUBLE; - ret_val = allocator.zero_allocate(1U, sizeof(double), allocator.state); - if (NULL == ret_val) { - return NULL; + if (style != YAML_SINGLE_QUOTED_SCALAR_STYLE && + style != YAML_DOUBLE_QUOTED_SCALAR_STYLE) + { + errno = 0; + endptr = NULL; + dval = strtod(value, &endptr); + if ((0 == errno) && (NULL != endptr)) { + if ((NULL != endptr) && (endptr != value)) { + if (('\0' != *value) && ('\0' == *endptr)) { + *val_type = DATA_TYPE_DOUBLE; + ret_val = allocator.zero_allocate(1U, sizeof(double), allocator.state); + if (NULL == ret_val) { + return NULL; + } + *((double *)ret_val) = dval; + return ret_val; } - *((double *)ret_val) = dval; - return ret_val; } } + errno = 0; } - errno = 0; /// It is a string *val_type = DATA_TYPE_STRING;