trafodion-codereview mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaveBirdsall <...@git.apache.org>
Subject [GitHub] trafodion pull request #1747: [TRAFODION-3235] add div and trim function for...
Date Mon, 19 Nov 2018 17:47:03 GMT
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1747#discussion_r234717573
  
    --- Diff: core/conn/odb/src/odb.c ---
    @@ -14685,6 +14743,56 @@ static void addGlobalPointer(void *ptr)
         globalPointers[nGlobalPointers++] = ptr;
     }
     
    +/* is_valid_numeric:
    +*      check if the string is valid numeric
    +*
    +*      Input: str: string to be validate.
    +*      Input: n: length of str
    +*
    +*      return: if str is valid numeric return 1 else return 0
    +*/
    +static int is_valid_numeric(const char* str, size_t n) {
    +    int s = 1;
    +    for (size_t i = 0; i < n; ++i) {
    +        switch (s) {
    +        case 1:
    +            if (str[i] == '+' || str[i] == '-') s = 2;
    +            else if (isdigit(str[i])) s = 3;
    +            else return 0;
    +            break;
    +        case 2:
    +            if (!isdigit(str[i])) return 0;
    +            s = 3;
    +            break;
    +        case 3:
    +            if (str[i] == '.') s = 4;
    +            else if (str[i] == 'e') s = 6;
    +            else if (!isdigit(str[i])) return 0;
    +            break;
    +        case 4:
    +            if (!isdigit(str[i])) return 0;
    +            s = 5;
    +            break;
    +        case 5:
    +            if (str[i] == 'e') s = 6;
    +            else if (!isdigit(str[i])) return 0;
    +            break;
    +        case 6:
    +            if (str[i] == '+' || str[i] == '-') s = 7;
    +            else if (isdigit(str[i])) s = 7;
    +            else return 0;
    +            break;
    +        case 7:
    +            if (!isdigit(str[i])) return 0;
    +            break;
    +        default:
    +            return 0;
    +        }
    +    }
    +    if (s == 3 || s == 7 || s == 5) return 1;
    --- End diff --
    
    I am wondering if s == 4 should be allowed here too. Consider the string "1234."


---

Mime
View raw message