In browser on oled, add '<' for readonly files

fix potential out by error/buffer overflow
This commit is contained in:
penfold42 2018-07-30 22:24:07 +10:00
parent 5fbfe85862
commit 0ddf2a6e0a

View file

@ -88,8 +88,8 @@ void FileBrowser::BrowsableListView::RefreshLine(u32 entryIndex, u32 x, u32 y, b
RGBA BkColour = RGBA(0, 0, 0, 0xFF); //palette[VIC2_COLOUR_INDEX_BLUE]; RGBA BkColour = RGBA(0, 0, 0, 0xFF); //palette[VIC2_COLOUR_INDEX_BLUE];
u32 columnsMax = columns; u32 columnsMax = columns;
if (columnsMax > sizeof(buffer1)) if (columnsMax > sizeof(buffer1)-1)
columnsMax = sizeof(buffer1); columnsMax = sizeof(buffer1)-1;
if (entryIndex < list->entries.size()) if (entryIndex < list->entries.size())
{ {
@ -104,7 +104,7 @@ void FileBrowser::BrowsableListView::RefreshLine(u32 entryIndex, u32 x, u32 y, b
{ {
char ROstring[8] = { 0 }; char ROstring[8] = { 0 };
if (entry->filImage.fattrib & AM_RDO) if (entry->filImage.fattrib & AM_RDO)
strncpy (ROstring, " R", 8); strncpy (ROstring, "<", 8);
if (entry->caddyIndex != -1) if (entry->caddyIndex != -1)
snprintf(buffer2, 256, "%d>%s%s" snprintf(buffer2, 256, "%d>%s%s"
, entry->caddyIndex , entry->caddyIndex
@ -157,7 +157,7 @@ void FileBrowser::BrowsableListView::RefreshLine(u32 entryIndex, u32 x, u32 y, b
} }
else else
{ {
memset(buffer1, ' ', 80); memset(buffer1, ' ', columnsMax);
screen->PrintText(false, x, y, buffer1, BkColour, BkColour); screen->PrintText(false, x, y, buffer1, BkColour, BkColour);
} }
} }
@ -203,10 +203,17 @@ void FileBrowser::BrowsableListView::RefreshHighlightScroll()
} }
else else
{ {
char ROstring[8] = { 0 };
if (entry->filImage.fattrib & AM_RDO)
strncpy (ROstring, "<", 8);
if (entry->caddyIndex != -1) if (entry->caddyIndex != -1)
snprintf(buffer2, 256, "%d>%s", entry->caddyIndex, entry->filImage.fname); snprintf(buffer2, 256, "%d>%s%s"
, entry->caddyIndex
, entry->filImage.fname
, ROstring
);
else else
snprintf(buffer2, 256, "%s", entry->filImage.fname); snprintf(buffer2, 256, "%s%s", entry->filImage.fname, ROstring);
} }
} }
else else