소스 검색

Fixed %p formatting when there is following text

Sam Lantinga 1 년 전
부모
커밋
f4bd17deee
2개의 변경된 파일7개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 3
      src/stdlib/SDL_string.c
  2. 6 0
      test/testautomation_stdlib.c

+ 1 - 3
src/stdlib/SDL_string.c

@@ -1922,6 +1922,7 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *f
                 case 'p':
                     info.force_case = SDL_CASE_LOWER;
                     length += SDL_PrintPointer(TEXT_AND_LEN_ARGS, &info, va_arg(ap, void *));
+                    done = SDL_TRUE;
                     break;
                 case 'x':
                     info.force_case = SDL_CASE_LOWER;
@@ -1933,9 +1934,6 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *f
                     if (info.radix == 10) {
                         info.radix = 16;
                     }
-                    if (*fmt == 'p') {
-                        inttype = DO_LONG;
-                    }
                     SDL_FALLTHROUGH;
                 case 'o':
                     if (info.radix == 10) {

+ 6 - 0
test/testautomation_stdlib.c

@@ -220,6 +220,12 @@ static int stdlib_snprintf(void *arg)
     SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
     SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
 
+    result = SDL_snprintf(text, sizeof(text), "A %p B", (void *)0x1234abcd);
+    expected = "A 0x1234abcd B";
+    SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"A %%p B\", 0x1234abcd)");
+    SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
+    SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
+
     return TEST_COMPLETED;
 }