This commit is contained in:
Wolfvak 2019-12-17 16:33:10 -03:00 committed by d0k3
parent 42f7fcfb7b
commit 9f50d2f03c
2 changed files with 23 additions and 17 deletions

View File

@ -151,7 +151,7 @@ u64 IdentifyFileType(const char* path) {
return BIN_LEGKEY; // legacy key file return BIN_LEGKEY; // legacy key file
} else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) { } else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) {
u64 type = 0; u64 type = 0;
if ((fsize <= SCRIPT_MAX_SIZE) && (strncasecmp(ext, SCRIPT_EXT, strnlen(SCRIPT_EXT, 16) + 1) == 0)) if ((fsize < SCRIPT_MAX_SIZE) && (strncasecmp(ext, SCRIPT_EXT, strnlen(SCRIPT_EXT, 16) + 1) == 0))
type |= TXT_SCRIPT; // should be a script (which is also generic text) type |= TXT_SCRIPT; // should be a script (which is also generic text)
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC; if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
return type; return type;

View File

@ -260,10 +260,13 @@ static inline u32 line_len(const char* text, u32 len, u32 ww, const char* line,
char* lf = NULL; char* lf = NULL;
char* spc = NULL; char* spc = NULL;
if (line >= (text + len))
return 0; // early exit
// search line feeds, spaces (only relevant for wordwrapped) // search line feeds, spaces (only relevant for wordwrapped)
for (llen = 0; !ww || (llen < ww); llen++) { for (llen = 0; !ww || (llen < ww); llen++) {
if (ww && (line[llen] == ' ')) spc = (char*) (line + llen); if (ww && (line[llen] == ' ')) spc = (char*) (line + llen);
if (!line[llen] || (line[llen] == '\n') || (llen == last)) { if (!line[llen] || (line[llen] == '\n') || (llen >= last)) {
lf = (char*) (line + llen); lf = (char*) (line + llen);
break; break;
} }
@ -1769,12 +1772,15 @@ bool MemToCViewer(const char* text, u32 len, const char* title) {
bool FileTextViewer(const char* path, bool as_script) { bool FileTextViewer(const char* path, bool as_script) {
// load text file (completely into memory) // load text file (completely into memory)
// text file needs to fit inside the STD_BUFFER_SIZE // text file needs to fit inside the STD_BUFFER_SIZE
char* text = (char*) malloc(STD_BUFFER_SIZE); u32 flen, len;
char* text = malloc(STD_BUFFER_SIZE);
if (!text) return false; if (!text) return false;
u32 flen = FileGetData(path, text, STD_BUFFER_SIZE, 0); flen = FileGetData(path, text, STD_BUFFER_SIZE - 1, 0);
u32 len = 0; // actual length may be shorter due to zero symbol
for (len = 0; (len < flen) && text[len]; len++); text[flen] = '\0';
len = (ptrdiff_t)memchr(text, '\0', flen + 1) - (ptrdiff_t)text;
// let MemTextViewer take over // let MemTextViewer take over
bool result = MemTextViewer(text, len, 1, as_script); bool result = MemTextViewer(text, len, 1, as_script);