Skip to content

Commit 19a4658

Browse files
authored
Merge pull request #358 from SilverNexus2/fix-pspdebugkb
Fix the debug keyboard failing to type.
2 parents d37d1e6 + cf963fb commit 19a4658

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)