Skip to content

Commit

Permalink
Replace any non alphanumerical character with '_' for output filenames (
Browse files Browse the repository at this point in the history
#246)

Fixes dumping carts with headers that have random garbage data in their gameTitle that are not actually ascii characters, thus making the dump fail because the output file cannot be opened
  • Loading branch information
edo9300 authored Nov 21, 2024
1 parent 87d623c commit e94a930
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions arm9/source/dumpOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "screenshot.h"
#include "version.h"

#include <cctype>
#include <dirent.h>
#include <nds.h>
#include <nds/arm9/dldi.h>
Expand Down Expand Up @@ -825,18 +826,8 @@ void ndsCardDump(void) {
sprintf(gameTitle, "NO-TITLE");
} else {
for(uint i = 0; i < sizeof(gameTitle); i++) {
switch(gameTitle[i]) {
case '>':
case '<':
case ':':
case '"':
case '/':
case '\x5C':
case '|':
case '?':
case '*':
gameTitle[i] = '_';
}
if(!isalnum(gameTitle[i]))
gameTitle[i] = '_';
}
}
if (gameCode[0] == 0 || gameCode[0] == 0x23 || gameCode[0] == 0xFF) {
Expand Down

2 comments on commit e94a930

@ApacheThunder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix seems to not catch "?" characters. I had a few dumpable carts no longer dumpable after this commit. :(

@edo9300
Copy link
Contributor Author

@edo9300 edo9300 commented on e94a930 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird, since as per the standard https://en.cppreference.com/w/cpp/string/byte/isalnum

Checks if the given character is an alphanumeric character as classified by the current C locale. In the default locale, the following characters are alphanumeric:

digits (0123456789)
uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
lowercase letters (abcdefghijklmnopqrstuvwxyz)

So the function should return 0 for ?

Please sign in to comment.