Buggy warning message "Record/Alias name '...' should not contain non-printable ...

Bug #1941875 reported by Dirk Zimoch
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
EPICS Base
Fix Released
Low
mdavidsaver

Bug Description

There are multiple bugs in dbRecordNameValidate() (modules/database/src/ioc/dbStatic/dbLexRoutines.c).

/* any character restrictions */
char c = *pos;
[...]
if(c < ' ') {
  errlogPrintf("Warning: Record/Alias name '%s' should not contain non-printable 0x%02u\n",
                         name, (unsigned)c);
}

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.

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :
Revision history for this message
mdavidsaver (mdavidsaver) wrote :

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).

Changed in epics-base:
status: New → Confirmed
importance: Undecided → Low
assignee: nobody → mdavidsaver (mdavidsaver)
Revision history for this message
mdavidsaver (mdavidsaver) wrote :

Patch applied as 42d06d6a38fd08d49daa28e782525393b5c8d82c

Changed in epics-base:
status: Confirmed → Fix Committed
milestone: none → 7.0.6.1
Andrew Johnson (anj)
Changed in epics-base:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.