Double-checked the test hex strings and their positions of illegal whitespace 
chars, here the native
routine with the corrected position:

    int64_t hex2char(RexxCallContext *rcc, CSTRING hexData, size_t len, char 
*data)
    {
        // check for trailing whitespace
        char tmp=(hexData[len-1]);      // get last character (must not be 
whitespace)
        if (tmp==' ' || tmp=='\t')
            rcc->ThrowException1(93931, rcc->UnsignedInt64ToObject(len));

        size_t dIdx=0;

        for (size_t i=0; i<len; i++)
        {

            if      (hexData[i]>='0' && hexData[i]<='9') tmp=hexData[i]-'0';
            else if (hexData[i]>='A' && hexData[i]<='F') tmp=hexData[i]-'A'+10;
            else if (hexData[i]>='a' && hexData[i]<='f') tmp=hexData[i]-'a'+10;
            else
            {
                // check for leading whitespace
                if (dIdx==0 && (hexData[i]==' ' || hexData[i]=='\t') )
                    rcc->ThrowException1(93931, rcc->Int32ToObject(1));

                if (hexData[i]==' ' || hexData[i]=='\t') continue; // skip on 
whitespace

                // illegal hex digit
                char buf[64];
                snprintf(buf, 64, "%c\0", hexData[i]);
                rcc->ThrowException1(93933, rcc->NewStringFromAsciiz(buf));
            }
            tmp<<=4;    // shift to high order nibble
            i++;        // position on next hex digit

            if (i==len) // we are beyond the hex string and missing the second 
hex digit
            {
                char buf[256];
                snprintf(buf, 256, "Hexadecimal string incomplete: hexadecimal 
pair starting with the character \"%c\" in position %zd is missing the second 
hexadecimal digit\0", hexData[i-1], len);
                rcc->ThrowException1(93900,rcc->NewStringFromAsciiz(buf));
            }


            if      (hexData[i]>='0' && hexData[i]<='9') tmp|=hexData[i]-'0';
            else if (hexData[i]>='A' && hexData[i]<='F') tmp|=hexData[i]-'A'+10;
            else if (hexData[i]>='a' && hexData[i]<='f') tmp|=hexData[i]-'a'+10;
            else if (hexData[i]==' ' || hexData[i]=='\t')  // also whitespace 
not allowed in between of a hex pair
                    rcc->ThrowException1(93931, 
rcc->UnsignedInt64ToObject(i*+1*));
            else // illegal hex digit
            {
                char buf[64];
                snprintf(buf, 64, "%c\0", hexData[i]);
                rcc->ThrowException1(93933, rcc->NewStringFromAsciiz(buf));
            }
            data[dIdx++]=tmp;
        }
        data[dIdx]='\0';
        return (int64_t)dIdx;            // return number or characters in data
    }

---rony

_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to