diff --git a/src/rcheevos/memref.c b/src/rcheevos/memref.c index 380ae0cf..038ea935 100644 --- a/src/rcheevos/memref.c +++ b/src/rcheevos/memref.c @@ -107,7 +107,12 @@ int rc_parse_memref(const char** memaddr, uint8_t* size, uint32_t* address) { /* case 'y': case 'Y': 64 bit? */ /* case 'z': case 'Z': 128 bit? */ - case '0': case '1': case '2': case '3': case '4': + case '0': + if (*aux == 'x') /* user mistyped an extra 0x: 0x0xabcd */ + return RC_INVALID_MEMORY_OPERAND; + /* fallthrough */ + + case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': diff --git a/test/rcheevos/test_operand.c b/test/rcheevos/test_operand.c index 60bd1d9e..ed12fe04 100644 --- a/test/rcheevos/test_operand.c +++ b/test/rcheevos/test_operand.c @@ -187,6 +187,9 @@ static void test_parse_memory_references() { TEST_PARAMS4(test_parse_operand, "0xHABCD", RC_OPERAND_ADDRESS, RC_MEMSIZE_8_BITS, 0xABCDU); TEST_PARAMS4(test_parse_operand, "0xhabcd", RC_OPERAND_ADDRESS, RC_MEMSIZE_8_BITS, 0xABCDU); TEST_PARAMS4(test_parse_operand, "fFABCD", RC_OPERAND_ADDRESS, RC_MEMSIZE_FLOAT, 0xABCDU); + + /* doubled up prefix */ + TEST_PARAMS3(test_parse_error_operand, "0x0xH1234", 0, RC_INVALID_MEMORY_OPERAND); } static void test_parse_delta_memory_references() { diff --git a/test/rcheevos/test_richpresence.c b/test/rcheevos/test_richpresence.c index 82d05648..d6388284 100644 --- a/test/rcheevos/test_richpresence.c +++ b/test/rcheevos/test_richpresence.c @@ -390,6 +390,12 @@ static void test_conditional_display_unnecessary_measured_indirect() { assert_richpresence_output(richpresence, &memory, "True"); } +static void test_conditional_display_invalid() { + int lines_read = 0; + ASSERT_NUM_EQUALS(rc_richpresence_size_lines("Display:\n?I:0x0x0000=1?True\nFalse\n", &lines_read), RC_INVALID_MEMORY_OPERAND); + ASSERT_NUM_EQUALS(lines_read, 2); +} + static void test_macro_value_adjusted_negative() { uint8_t ram[] = { 0x00, 0x12, 0x34, 0xAB, 0x56 }; memory_t memory; @@ -526,6 +532,10 @@ static void test_macro_value_remember_recall() { assert_richpresence_output(richpresence, &memory, "Result is 3"); } +static void test_macro_value_invalid() { + ASSERT_NUM_EQUALS(rc_richpresence_size("Format:Points\nFormatType=VALUE\n\nDisplay:\n@Points(0x0x0001) Points"), RC_INVALID_MEMORY_OPERAND); +} + static void test_macro_hundreds() { uint8_t ram[] = { 0x00, 0x12, 0x34, 0xAB, 0x56 }; memory_t memory; @@ -1342,6 +1352,7 @@ void test_richpresence(void) { TEST(test_conditional_display_indirect); TEST(test_conditional_display_unnecessary_measured); TEST(test_conditional_display_unnecessary_measured_indirect); + TEST(test_conditional_display_invalid); /* value macros */ TEST(test_macro_value); @@ -1355,6 +1366,7 @@ void test_richpresence(void) { TEST(test_macro_value_divide_by_zero); TEST(test_macro_value_divide_by_self); TEST(test_macro_value_remember_recall); + TEST(test_macro_value_invalid); /* hundreds macro */ TEST(test_macro_hundreds);