Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy in Error Messages: INT vs UINT out of range #247

Open
Semnodime opened this issue Oct 2, 2024 · 3 comments
Open

Discrepancy in Error Messages: INT vs UINT out of range #247

Semnodime opened this issue Oct 2, 2024 · 3 comments

Comments

@Semnodime
Copy link

libcyaml: ERROR: Load: INT value out of range: '128'
libcyaml: ERROR: Load: Invalid UINT value: '256'
https://github.com/tlsa/libcyaml/blob/c9956cbb50772ecc10fcf6a8ab210cce60e17567/src/load.c#L231C1-L236C3

@tlsa
Copy link
Owner

tlsa commented Oct 2, 2024

Thanks I'll fix it later!

@Semnodime
Copy link
Author

Notice that for signed integers, the distinct messages are symptoms of two different error cases:

typedef struct {
    int8_t *bar;
} foo_t;


static const cyaml_schema_field_t schema[] = {
    CYAML_FIELD_INT_PTR("bar", CYAML_FLAG_POINTER_NULL_STR, foo_t, bar)
    CYAML_FIELD_END
};

On my x64 system, "valid INT values" are [- 2^63 … 2^63 - 1] (signed int64_t).
This is due to the underlying conversion of the string to an integer, where the Invalid INT value error indicates that an INT (a word of the target platform?) cannot hold the value.
Since the target field in the foo_t struct is of size 8 bit, the different error message informs the user, that it cannot hold a value outside of [-2^7 … 2^7 - 1]

libcyaml: ERROR: Load: Invalid INT value: '-9223372036854775809' (- 2^63 - 1)
libcyaml: ERROR: Load: INT value out of range: '-9223372036854775808' (- 2^63)
libcyaml: ERROR: Load: INT value out of range: '-129' (- 2^7 - 1)
-128 is ok (- 2^7)
127 is ok (+ 2^7 - 1)
libcyaml: ERROR: Load: INT value out of range: '128' (+ 2^7)
libcyaml: ERROR: Load: INT value out of range: '9223372036854775807' (2^63 - 1)
libcyaml: ERROR: Load: Invalid INT value: '9223372036854775808' (- 2^63)

@tlsa
Copy link
Owner

tlsa commented Oct 2, 2024

Please try this: #248 and let me know if it works okay for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants