Skip to content

Commit

Permalink
fru_get_typelen: Fix autodetection of binary
Browse files Browse the repository at this point in the history
TAB, CR and LF symbols were not considered text
and were forcing binary encoding to be used.
That is fixed now. Any data containing pure text
and the above characters will now be reported as
8-bit ASCII (plain text).

frugen will not encode text with those characters
as binary as it would before this commit.

Signed-off-by: Alexander Amelkin <a.amelkin@yadro.com>
  • Loading branch information
AlexanderAmelkin committed Mar 19, 2021
1 parent d2919aa commit 57bf60b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions fru.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ uint8_t fru_get_typelen(int len, /**< [in] Length of the data or LEN

// Go through the data and expand charset as needed
for (i = 0; i < len; i++) {
if (data[i] < ' ') {
if (data[i] < ' '
&& data[i] != '\t'
&& data[i] != '\r'
&& data[i] != '\n')
{
// They lied! The data is binary!
// That's the widest range type.
// There is no use in checking any further.
Expand All @@ -108,7 +112,9 @@ uint8_t fru_get_typelen(int len, /**< [in] Length of the data or LEN
break;
}

if (typelen < FRU_MAKETYPE(TEXT) && data[i] > '_') { // Do not reduce the range
if (typelen < FRU_MAKETYPE(TEXT)
&& (data[i] > '_' || data[i] < ' '))
{ // Do not reduce the range
// The data doesn't fit into 6-bit ASCII, expand to simple text.
DEBUG("[%c] Data is simple text!\n", data[i]);
typelen = FRU_TYPELEN(TEXT, len);
Expand Down

0 comments on commit 57bf60b

Please sign in to comment.