forked from Mirror/GodMode9
Fix #573
This commit is contained in:
parent
42f7fcfb7b
commit
9f50d2f03c
@ -151,7 +151,7 @@ u64 IdentifyFileType(const char* path) {
|
||||
return BIN_LEGKEY; // legacy key file
|
||||
} else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) {
|
||||
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)
|
||||
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
|
||||
return type;
|
||||
|
@ -260,10 +260,13 @@ static inline u32 line_len(const char* text, u32 len, u32 ww, const char* line,
|
||||
char* lf = NULL;
|
||||
char* spc = NULL;
|
||||
|
||||
if (line >= (text + len))
|
||||
return 0; // early exit
|
||||
|
||||
// search line feeds, spaces (only relevant for wordwrapped)
|
||||
for (llen = 0; !ww || (llen < ww); 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);
|
||||
break;
|
||||
}
|
||||
@ -1769,12 +1772,15 @@ bool MemToCViewer(const char* text, u32 len, const char* title) {
|
||||
bool FileTextViewer(const char* path, bool as_script) {
|
||||
// load text file (completely into memory)
|
||||
// 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;
|
||||
|
||||
u32 flen = FileGetData(path, text, STD_BUFFER_SIZE, 0);
|
||||
u32 len = 0; // actual length may be shorter due to zero symbol
|
||||
for (len = 0; (len < flen) && text[len]; len++);
|
||||
flen = FileGetData(path, text, STD_BUFFER_SIZE - 1, 0);
|
||||
|
||||
text[flen] = '\0';
|
||||
len = (ptrdiff_t)memchr(text, '\0', flen + 1) - (ptrdiff_t)text;
|
||||
|
||||
// let MemTextViewer take over
|
||||
bool result = MemTextViewer(text, len, 1, as_script);
|
||||
|
Loading…
x
Reference in New Issue
Block a user