From b5e8e4dc2bdeca39195a78d8d7f01bd7f099923c Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周五, 13 11月 2015 18:54:29 +0800 Subject: [PATCH] Resolve #65: Cast char to unsigned in isctype functions --- libscpi/src/units.c | 38 ++++++++++++++++++++++++-------------- 1 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libscpi/src/units.c b/libscpi/src/units.c index 792df76..f59fe86 100644 --- a/libscpi/src/units.c +++ b/libscpi/src/units.c @@ -38,6 +38,7 @@ #include "scpi/parser.h" #include "scpi/units.h" #include "utils_private.h" +#include "scpi/utils.h" #include "scpi/error.h" #include "lexer_private.h" @@ -112,6 +113,7 @@ {/* name */ "NAN", /* type */ SCPI_NUM_NAN}, {/* name */ "INFinity", /* type */ SCPI_NUM_INF}, {/* name */ "NINF", /* type */ SCPI_NUM_NINF}, + {/* name */ "AUTO", /* type */ SCPI_NUM_AUTO}, SCPI_CHOICE_LIST_END, }; @@ -198,13 +200,12 @@ * @param mandatory if the parameter is mandatory * @return */ -scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory) -{ +scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory) { scpi_token_t token; lex_state_t state; scpi_parameter_t param; scpi_bool_t result; - int32_t intval; + int32_t tag; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); @@ -221,7 +222,7 @@ state.pos = state.buffer; state.len = param.len; - switch(param.type) { + switch (param.type) { case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_HEXNUM: case SCPI_TOKEN_OCTNUM: @@ -229,12 +230,14 @@ case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: case SCPI_TOKEN_PROGRAM_MNEMONIC: value->unit = SCPI_UNIT_NONE; - value->type = SCPI_NUM_NUMBER; + value->special = FALSE; result = TRUE; + break; + default: break; } - switch(param.type) { + switch (param.type) { case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: case SCPI_TOKEN_PROGRAM_MNEMONIC: @@ -249,9 +252,11 @@ case SCPI_TOKEN_OCTNUM: value->base = 8; break; + default: + break; } - switch(param.type) { + switch (param.type) { case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: SCPI_ParamToDouble(context, ¶m, &(value->value)); break; @@ -278,10 +283,10 @@ scpiLex_CharacterProgramData(&state, &token); /* convert string to special number type */ - SCPI_ParamToChoice(context, &token, special, &intval); + result = SCPI_ParamToChoice(context, &token, special, &tag); - value->type = intval; - value->value = 0; + value->special = TRUE; + value->tag = tag; break; default: @@ -308,12 +313,17 @@ return 0; } - if (SCPI_ChoiceToName(special, value->type, &type)) { - strncpy(str, type, len); - return min(strlen(type), len); + if (value->special) { + if (SCPI_ChoiceToName(special, value->tag, &type)) { + strncpy(str, type, len); + return min(strlen(type), len); + } else { + str[0] = 0; + return 0; + } } - result = doubleToStr(value->value, str, len); + result = SCPI_DoubleToStr(value->value, str, len); unit = translateUnitInverse(context->units, value->unit); -- Gitblit v1.9.1