ENGINE-614: ok, sscanf isn't as happy scanning into strings as you might imagine XD ENGINE-614
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Thu, 08 Aug 2019 14:37:16 +0200
branchENGINE-614
changeset 3972418467283c3f
parent 3968 7bef1333235a
child 3973 7f5f08c3e9b4
child 3974 8628026434fc
ENGINE-614: ok, sscanf isn't as happy scanning into strings as you might imagine XD
src/pEpEngine.c
     1.1 --- a/src/pEpEngine.c	Thu Aug 08 11:56:11 2019 +0200
     1.2 +++ b/src/pEpEngine.c	Thu Aug 08 14:37:16 2019 +0200
     1.3 @@ -1498,11 +1498,32 @@
     1.4                  // N.B. WE DEFINE PEP_VERSION - IF WE'RE AT 9-DIGIT MAJOR OR MINOR VERSIONS, ER, BAD.
     1.5                  char major_buf[10];
     1.6                  char minor_buf[10];
     1.7 -                if (sscanf(PEP_VERSION, "%s.%s", major_buf, minor_buf) != 2)
     1.8 -                    return PEP_UNKNOWN_ERROR; // DO BETTER
     1.9 -                size_t major_len = strlen(major_buf);
    1.10 -                size_t minor_len = strlen(minor_buf);
    1.11 -                    
    1.12 +                
    1.13 +                // Guess we were abusing sscanf here, so we'll do it this way:
    1.14 +                const char* cptr = PEP_VERSION;
    1.15 +                size_t major_len = 0;
    1.16 +                size_t minor_len = 0;
    1.17 +                
    1.18 +                char* bufptr = major_buf;
    1.19 +                while (*cptr != '.' && *cptr != '\0') {
    1.20 +                    *bufptr++ = *cptr++;
    1.21 +                    major_len++;
    1.22 +                }
    1.23 +                *bufptr = '\0';
    1.24 +                bufptr = minor_buf;
    1.25 +
    1.26 +                if (*cptr == '.') {
    1.27 +                    cptr++;
    1.28 +                    while (*cptr != '\0') {
    1.29 +                        *bufptr++ = *cptr++;
    1.30 +                        minor_len++;
    1.31 +                    }
    1.32 +                }
    1.33 +                else {
    1.34 +                    *bufptr++ = '0';
    1.35 +                }
    1.36 +                *bufptr = '\0';
    1.37 +                                    
    1.38                  const char* _ver_12_startstr =                     
    1.39                      "update identity\n"
    1.40                      "    set pEp_version_major = ";