Skip to content

Commit cf963fb

Browse files
committed
Fix the debug keyboard failing to type.
A bug introduced in 332dd43 caused the keyboard to locally modify the source strings, and then discard the changes without writing them back to the original string. This change drops the use of snprintf to perform the changes entirely, opting instead for twiddling the characters in-place. This required changing the bounds check to ensure there remains room for the null-terminator, and a call to strlen was refactored to be stored for the local scope.
1 parent d37d1e6 commit cf963fb

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/debug/pspdebugkb.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,17 @@ void pspDebugKbInit(char* str) {
249249
pspDebugKbShift(&shifted);
250250
pspDebugKbDrawKey(row, col, 1);
251251
break;
252-
case 1: // Space
253-
if (strlen(str) < PSP_DEBUG_KB_MAXLEN) {
254-
char out[PSP_DEBUG_KB_MAXLEN + 2];
255-
snprintf(out, sizeof(out), "%s ", str);
256-
pspDebugKbDrawString(out);
252+
// Using the curly braces so we have an anonymous code block so we can declare a stack variable
253+
case 1: { // Space
254+
size_t len = strlen(str);
255+
if (len < PSP_DEBUG_KB_MAXLEN-1) {
256+
// Add the character to the still-in-bounds string
257+
str[len] = ' ';
258+
str[len+1] = '\0';
259+
pspDebugKbDrawString(str);
257260
}
258261
break;
262+
}
259263
case 2: // Back
260264
if (strlen(str) > 0) {
261265
str[strlen(str)-1] = '\0';
@@ -272,10 +276,14 @@ void pspDebugKbInit(char* str) {
272276
return;
273277
};
274278
} else {
275-
if (strlen(str) < PSP_DEBUG_KB_MAXLEN) {
276-
char out[PSP_DEBUG_KB_MAXLEN + 2];
277-
snprintf(out, sizeof(out), "%s%c", str, charTable[row][col]);
278-
pspDebugKbDrawString(out);
279+
size_t len = strlen(str);
280+
// Leave room for null terminator
281+
if (len < PSP_DEBUG_KB_MAXLEN-1) {
282+
// Add the character to the still-in-bounds string
283+
str[len] = charTable[row][col];
284+
str[len+1] = '\0';
285+
// Display the string
286+
pspDebugKbDrawString(str);
279287
}
280288
}
281289
}

0 commit comments

Comments
 (0)