Buggy warning message "Record/Alias name '...' should not contain non-printable ...
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
EPICS Base |
Fix Released
|
Low
|
mdavidsaver |
Bug Description
There are multiple bugs in dbRecordNameVal
/* any character restrictions */
char c = *pos;
[...]
if(c < ' ') {
errlogPrintf(
}
1. The check for non-printable characters: if(c < ' ') does not consider implementations where char is signed. Characters with the high bit set are considered negative and thus <' '.
2. Printing the character with "0x%02u" prints a decimal number prefixed with 0x which is confusing (not to say wrong).
3. Casting a signed char to unsigned effectively first sign extends the char to int, then re-interprets it as unsigned int, turning a char >0x80 into a number >4294967168.
On an implementation where char is unsigned, the whole casting is pointless anyway.
This results in confusing warnings like:
Warning: Record/Alias name 'Ä' should not contain non-printable 0x4294967235
The function should explicitly use unsigned char c to fix (c < ' '), use "0x%02x" to format c and not cast c.
Changed in epics-base: | |
status: | New → Confirmed |
importance: | Undecided → Low |
assignee: | nobody → mdavidsaver (mdavidsaver) |
Changed in epics-base: | |
status: | Fix Committed → Fix Released |
The attached patch looks reasonable to me.
I wondered briefly about how "c < ' '" wrt. type promotion. I think this would promote 'c' from 'unsigned char' to 'int', which should work as intended (excluding char in the range 0 -> 32).