Error with 'le_utf8_ParseInt'


#1

Hi,

I’ve encountered an issue when using the function le_utf8_ParseInt to parse numerical strings with more than 1 leading zero (‘0’).

Here’s a basic test app attempting to parse strings ranging from ‘000’ to ‘255’ which illustrates the problem:

#include "legato.h"
#include <stdio.h>
#include <stdint.h>

COMPONENT_INIT
{
    LE_INFO("UTF-8 Parse Int Test");

    char numString[10] = "000";

    LE_INFO("Size of 'int' = %d", sizeof(int));

    for(uint16_t i = 0; i < 256; i++)
    {
		snprintf(numString, sizeof(numString)-1, "%03u", i);

		if ( ! le_utf8_IsFormatCorrect(numString) )
		{
			LE_INFO("String is not UTF-8 encoded.");
		}
		else
		{
		        int val = 0;
			le_result_t res = le_utf8_ParseInt(&val, numString);
			LE_INFO("Number string = %s, UTF-8 parsed int = %d, Result code = %d", numString, val, res);
		}
    }
}

And here’s the output from the Legato Console:

Dec  2 01:04:26 | Legato | == Starting Event Processing Loop ==
Dec  2 01:04:26 | Legato | UTF-8 Parse Int Test
Dec  2 01:04:26 | Legato | Size of 'int' = 4
Dec  2 01:04:26 | Legato | Number string = 000, UTF-8 parsed int = 0, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 001, UTF-8 parsed int = 1, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 002, UTF-8 parsed int = 2, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 003, UTF-8 parsed int = 3, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 004, UTF-8 parsed int = 4, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 005, UTF-8 parsed int = 5, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 006, UTF-8 parsed int = 6, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 007, UTF-8 parsed int = 7, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 008, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 009, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 010, UTF-8 parsed int = 8, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 011, UTF-8 parsed int = 9, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 012, UTF-8 parsed int = 10, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 013, UTF-8 parsed int = 11, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 014, UTF-8 parsed int = 12, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 015, UTF-8 parsed int = 13, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 016, UTF-8 parsed int = 14, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 017, UTF-8 parsed int = 15, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 018, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 019, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 020, UTF-8 parsed int = 16, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 021, UTF-8 parsed int = 17, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 022, UTF-8 parsed int = 18, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 023, UTF-8 parsed int = 19, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 024, UTF-8 parsed int = 20, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 025, UTF-8 parsed int = 21, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 026, UTF-8 parsed int = 22, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 027, UTF-8 parsed int = 23, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 028, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 029, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 030, UTF-8 parsed int = 24, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 031, UTF-8 parsed int = 25, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 032, UTF-8 parsed int = 26, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 033, UTF-8 parsed int = 27, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 034, UTF-8 parsed int = 28, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 035, UTF-8 parsed int = 29, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 036, UTF-8 parsed int = 30, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 037, UTF-8 parsed int = 31, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 038, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 039, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 040, UTF-8 parsed int = 32, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 041, UTF-8 parsed int = 33, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 042, UTF-8 parsed int = 34, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 043, UTF-8 parsed int = 35, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 044, UTF-8 parsed int = 36, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 045, UTF-8 parsed int = 37, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 046, UTF-8 parsed int = 38, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 047, UTF-8 parsed int = 39, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 048, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 049, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 050, UTF-8 parsed int = 40, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 051, UTF-8 parsed int = 41, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 052, UTF-8 parsed int = 42, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 053, UTF-8 parsed int = 43, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 054, UTF-8 parsed int = 44, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 055, UTF-8 parsed int = 45, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 056, UTF-8 parsed int = 46, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 057, UTF-8 parsed int = 47, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 058, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 059, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 060, UTF-8 parsed int = 48, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 061, UTF-8 parsed int = 49, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 062, UTF-8 parsed int = 50, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 063, UTF-8 parsed int = 51, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 064, UTF-8 parsed int = 52, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 065, UTF-8 parsed int = 53, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 066, UTF-8 parsed int = 54, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 067, UTF-8 parsed int = 55, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 068, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 069, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 070, UTF-8 parsed int = 56, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 071, UTF-8 parsed int = 57, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 072, UTF-8 parsed int = 58, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 073, UTF-8 parsed int = 59, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 074, UTF-8 parsed int = 60, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 075, UTF-8 parsed int = 61, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 076, UTF-8 parsed int = 62, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 077, UTF-8 parsed int = 63, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 078, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 079, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 080, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 081, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 082, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 083, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 084, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 085, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 086, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 087, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 088, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 089, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 090, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 091, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 092, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 093, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 094, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 095, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 096, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 097, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 098, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 099, UTF-8 parsed int = 0, Result code = -13
Dec  2 01:04:26 | Legato | Number string = 100, UTF-8 parsed int = 100, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 101, UTF-8 parsed int = 101, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 102, UTF-8 parsed int = 102, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 103, UTF-8 parsed int = 103, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 104, UTF-8 parsed int = 104, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 105, UTF-8 parsed int = 105, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 106, UTF-8 parsed int = 106, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 107, UTF-8 parsed int = 107, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 108, UTF-8 parsed int = 108, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 109, UTF-8 parsed int = 109, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 110, UTF-8 parsed int = 110, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 111, UTF-8 parsed int = 111, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 112, UTF-8 parsed int = 112, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 113, UTF-8 parsed int = 113, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 114, UTF-8 parsed int = 114, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 115, UTF-8 parsed int = 115, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 116, UTF-8 parsed int = 116, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 117, UTF-8 parsed int = 117, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 118, UTF-8 parsed int = 118, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 119, UTF-8 parsed int = 119, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 120, UTF-8 parsed int = 120, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 121, UTF-8 parsed int = 121, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 122, UTF-8 parsed int = 122, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 123, UTF-8 parsed int = 123, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 124, UTF-8 parsed int = 124, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 125, UTF-8 parsed int = 125, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 126, UTF-8 parsed int = 126, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 127, UTF-8 parsed int = 127, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 128, UTF-8 parsed int = 128, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 129, UTF-8 parsed int = 129, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 130, UTF-8 parsed int = 130, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 131, UTF-8 parsed int = 131, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 132, UTF-8 parsed int = 132, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 133, UTF-8 parsed int = 133, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 134, UTF-8 parsed int = 134, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 135, UTF-8 parsed int = 135, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 136, UTF-8 parsed int = 136, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 137, UTF-8 parsed int = 137, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 138, UTF-8 parsed int = 138, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 139, UTF-8 parsed int = 139, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 140, UTF-8 parsed int = 140, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 141, UTF-8 parsed int = 141, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 142, UTF-8 parsed int = 142, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 143, UTF-8 parsed int = 143, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 144, UTF-8 parsed int = 144, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 145, UTF-8 parsed int = 145, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 146, UTF-8 parsed int = 146, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 147, UTF-8 parsed int = 147, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 148, UTF-8 parsed int = 148, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 149, UTF-8 parsed int = 149, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 150, UTF-8 parsed int = 150, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 151, UTF-8 parsed int = 151, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 152, UTF-8 parsed int = 152, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 153, UTF-8 parsed int = 153, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 154, UTF-8 parsed int = 154, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 155, UTF-8 parsed int = 155, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 156, UTF-8 parsed int = 156, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 157, UTF-8 parsed int = 157, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 158, UTF-8 parsed int = 158, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 159, UTF-8 parsed int = 159, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 160, UTF-8 parsed int = 160, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 161, UTF-8 parsed int = 161, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 162, UTF-8 parsed int = 162, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 163, UTF-8 parsed int = 163, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 164, UTF-8 parsed int = 164, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 165, UTF-8 parsed int = 165, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 166, UTF-8 parsed int = 166, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 167, UTF-8 parsed int = 167, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 168, UTF-8 parsed int = 168, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 169, UTF-8 parsed int = 169, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 170, UTF-8 parsed int = 170, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 171, UTF-8 parsed int = 171, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 172, UTF-8 parsed int = 172, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 173, UTF-8 parsed int = 173, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 174, UTF-8 parsed int = 174, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 175, UTF-8 parsed int = 175, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 176, UTF-8 parsed int = 176, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 177, UTF-8 parsed int = 177, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 178, UTF-8 parsed int = 178, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 179, UTF-8 parsed int = 179, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 180, UTF-8 parsed int = 180, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 181, UTF-8 parsed int = 181, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 182, UTF-8 parsed int = 182, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 183, UTF-8 parsed int = 183, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 184, UTF-8 parsed int = 184, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 185, UTF-8 parsed int = 185, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 186, UTF-8 parsed int = 186, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 187, UTF-8 parsed int = 187, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 188, UTF-8 parsed int = 188, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 189, UTF-8 parsed int = 189, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 190, UTF-8 parsed int = 190, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 191, UTF-8 parsed int = 191, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 192, UTF-8 parsed int = 192, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 193, UTF-8 parsed int = 193, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 194, UTF-8 parsed int = 194, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 195, UTF-8 parsed int = 195, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 196, UTF-8 parsed int = 196, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 197, UTF-8 parsed int = 197, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 198, UTF-8 parsed int = 198, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 199, UTF-8 parsed int = 199, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 200, UTF-8 parsed int = 200, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 201, UTF-8 parsed int = 201, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 202, UTF-8 parsed int = 202, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 203, UTF-8 parsed int = 203, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 204, UTF-8 parsed int = 204, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 205, UTF-8 parsed int = 205, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 206, UTF-8 parsed int = 206, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 207, UTF-8 parsed int = 207, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 208, UTF-8 parsed int = 208, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 209, UTF-8 parsed int = 209, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 210, UTF-8 parsed int = 210, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 211, UTF-8 parsed int = 211, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 212, UTF-8 parsed int = 212, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 213, UTF-8 parsed int = 213, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 214, UTF-8 parsed int = 214, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 215, UTF-8 parsed int = 215, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 216, UTF-8 parsed int = 216, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 217, UTF-8 parsed int = 217, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 218, UTF-8 parsed int = 218, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 219, UTF-8 parsed int = 219, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 220, UTF-8 parsed int = 220, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 221, UTF-8 parsed int = 221, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 222, UTF-8 parsed int = 222, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 223, UTF-8 parsed int = 223, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 224, UTF-8 parsed int = 224, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 225, UTF-8 parsed int = 225, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 226, UTF-8 parsed int = 226, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 227, UTF-8 parsed int = 227, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 228, UTF-8 parsed int = 228, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 229, UTF-8 parsed int = 229, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 230, UTF-8 parsed int = 230, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 231, UTF-8 parsed int = 231, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 232, UTF-8 parsed int = 232, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 233, UTF-8 parsed int = 233, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 234, UTF-8 parsed int = 234, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 235, UTF-8 parsed int = 235, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 236, UTF-8 parsed int = 236, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 237, UTF-8 parsed int = 237, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 238, UTF-8 parsed int = 238, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 239, UTF-8 parsed int = 239, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 240, UTF-8 parsed int = 240, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 241, UTF-8 parsed int = 241, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 242, UTF-8 parsed int = 242, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 243, UTF-8 parsed int = 243, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 244, UTF-8 parsed int = 244, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 245, UTF-8 parsed int = 245, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 246, UTF-8 parsed int = 246, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 247, UTF-8 parsed int = 247, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 248, UTF-8 parsed int = 248, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 249, UTF-8 parsed int = 249, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 250, UTF-8 parsed int = 250, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 251, UTF-8 parsed int = 251, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 252, UTF-8 parsed int = 252, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 253, UTF-8 parsed int = 253, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 254, UTF-8 parsed int = 254, Result code = 0
Dec  2 01:04:26 | Legato | Number string = 255, UTF-8 parsed int = 255, Result code = 0

The UTF-8 String Handling API is satisfied with the string formatting when using le_utf8_IsFormatCorrect but the parsing function thinks otherwise when it returns -13 (LE_FORMAT_ERROR) for some number strings.

I wasn’t able to find le_utf8.c to dig any deeper. Is this a known issue?
I noticed the test unit for le_utf8 doesn’t test for this condition - it only checks for a single leading zero.

BTW, I’m using Legato 16.07.

Cheers,
Raf


#2

The function is implemented in framework/c/src/utf8.c.

The implementation is based on strtol().

value = strtol(arg, &endPtr, 0);

Note that we use 0 as the base, which means it will auto-detect the numbering system (octal, decimal, hex). In your case, it sees the leading 0 and decides to use octal. So, any number that starts with 0 and contains an ‘8’ or ‘9’ is considered incorrectly formatted as a number. But, it’s still a correctly formatted UTF8 text string, so le_utf8_IsFormatCorrect() is happy with it. Once you hit 100, le_utf8_ParseInt() starts interpreting the value as decimal, because there are no leading zeros.

I see that the auto-detect feature is not documented on legato.io.

For now, you can copy the implementation and change the base to 10 if you want to force it to always be decimal. It might be nice to have a version of le_utf8_ParseInt() that parses decimals with leading zeros too. Maybe something like

le_utf8_ParseDecimalInt()?

I invite you to submit a pull request for that. :wink:

Cheers,

–Jen


#3

Passing 0 as a base to strtol in the implementation of le_utf8_parseInt is arguably a bug. I think there should be an explicit base parameter to le_utf8_ParseInt.

I also don’t like the fact that this function is not capable of parsing an integer from the beginning of a string. For example parsing “123Bike” leads to an error rather than 123 and a remainder of “Bike”.

Furthermore, I don’t like implementing this on top of strtol because strtol is imprecise. It consumes leading whitespace (but not trailing) without telling you. When you pass base 16 to it, it will silently consume 0x and 0X prefixes and there is no way to disable this.