Browse Source

Fixed assert when % is used in condition.

Бранимир Караџић 1 year ago
parent
commit
ad2c097987
2 changed files with 4 additions and 4 deletions
  1. 2 2
      include/bx/macros.h
  2. 2 2
      tests/macros_test.cpp

+ 2 - 2
include/bx/macros.h

@@ -285,7 +285,7 @@
 #define _BX_ASSERT(_condition, _format, ...)                                                                   \
 #define _BX_ASSERT(_condition, _format, ...)                                                                   \
 	BX_MACRO_BLOCK_BEGIN                                                                                       \
 	BX_MACRO_BLOCK_BEGIN                                                                                       \
 		if (!BX_IGNORE_C4127(_condition)                                                                       \
 		if (!BX_IGNORE_C4127(_condition)                                                                       \
-		&&  bx::assertFunction(bx::Location::current(), "ASSERT " #_condition " -> " _format, ##__VA_ARGS__) ) \
+		&&  bx::assertFunction(bx::Location::current(), "ASSERT %s -> " _format, #_condition, ##__VA_ARGS__) ) \
 		{                                                                                                      \
 		{                                                                                                      \
 			bx::debugBreak();                                                                                  \
 			bx::debugBreak();                                                                                  \
 		}                                                                                                      \
 		}                                                                                                      \
@@ -294,7 +294,7 @@
 #define _BX_ASSERT_LOC(_location, _condition, _format, ...)                                       \
 #define _BX_ASSERT_LOC(_location, _condition, _format, ...)                                       \
 	BX_MACRO_BLOCK_BEGIN                                                                          \
 	BX_MACRO_BLOCK_BEGIN                                                                          \
 		if  (!BX_IGNORE_C4127(_condition)                                                         \
 		if  (!BX_IGNORE_C4127(_condition)                                                         \
-		&&   bx::assertFunction(_location, "ASSERT " #_condition " -> " _format, ##__VA_ARGS__) ) \
+		&&   bx::assertFunction(_location, "ASSERT %s -> " _format, #_condition, ##__VA_ARGS__) ) \
 		{                                                                                         \
 		{                                                                                         \
 			bx::debugBreak();                                                                     \
 			bx::debugBreak();                                                                     \
 		}                                                                                         \
 		}                                                                                         \

+ 2 - 2
tests/macros_test.cpp

@@ -30,7 +30,7 @@ BX_NO_INLINE void unusedFunction()
 
 
 void testAssert()
 void testAssert()
 {
 {
-	BX_ASSERT(false, "Assert works!");
+	BX_ASSERT(false % 1, "Assert works!");
 }
 }
 
 
 TEST_CASE("Macros", "")
 TEST_CASE("Macros", "")
@@ -51,7 +51,7 @@ TEST_CASE("Macros", "")
 	REQUIRE(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
 	REQUIRE(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
 	REQUIRE(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
 	REQUIRE(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
 
 
-	REQUIRE(0 == bx::strCmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") );
+	REQUIRE(0 == bx::strCmp(BX_STRINGIZE(TEST 1234 % 1 ^&*), "TEST 1234 % 1 ^&*") );
 
 
 	{
 	{
 		struct PodStruct { int32_t x, y, z; };
 		struct PodStruct { int32_t x, y, z; };