Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more compiler flags #122

Merged
merged 7 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ if (ENABLE_CUSTOM_COMPILER_FLAGS)
-Wconversion
-Wc++-compat
-fstack-protector-strong
-Wcomma
-Wdouble-promotion
-Wparentheses
)
endif()

Expand Down
6 changes: 3 additions & 3 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int cJSON_strcasecmp(const unsigned char *s1, const unsigned char *s2)
{
return 1;
}
for(; tolower(*s1) == tolower(*s2); ++s1, ++s2)
for(; tolower(*s1) == tolower(*s2); (void)++s1, ++s2)
{
if (*s1 == '\0')
{
Expand Down Expand Up @@ -731,7 +731,7 @@ static unsigned char *print_string_ptr(const unsigned char * const input, printb
output[0] = '\"';
output_pointer = output + 1;
/* copy the string */
for (input_pointer = input; *input_pointer != '\0'; input_pointer++, output_pointer++)
for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++)
{
if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\'))
{
Expand Down Expand Up @@ -1914,7 +1914,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)

for(i = 0; a && (i < (size_t)count); i++)
{
n = cJSON_CreateNumber(numbers[i]);
n = cJSON_CreateNumber((double)numbers[i]);
if(!n)
{
cJSON_Delete(a);
Expand Down
18 changes: 9 additions & 9 deletions cJSON_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static int cJSONUtils_strcasecmp(const unsigned char *s1, const unsigned char *s
{
return 1;
}
for(; tolower(*s1) == tolower(*s2); ++s1, ++s2)
for(; tolower(*s1) == tolower(*s2); (void)++s1, ++s2)
{
if(*s1 == 0)
{
Expand All @@ -49,7 +49,7 @@ static int cJSONUtils_Pstrcasecmp(const unsigned char *a, const unsigned char *e
{
return (a == e) ? 0 : 1; /* both NULL? */
}
for (; *a && *e && (*e != '/'); a++, e++) /* compare until next '/' */
for (; *a && *e && (*e != '/'); (void)a++, e++) /* compare until next '/' */
{
if (*e == '~')
{
Expand Down Expand Up @@ -81,7 +81,7 @@ static int cJSONUtils_Pstrcasecmp(const unsigned char *a, const unsigned char *e
static size_t cJSONUtils_PointerEncodedstrlen(const unsigned char *s)
{
size_t l = 0;
for (; *s; s++, l++)
for (; *s; (void)s++, l++)
{
if ((*s == '~') || (*s == '/'))
{
Expand Down Expand Up @@ -127,7 +127,7 @@ CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *ta
}

/* recursively search all children of the object */
for (obj = object->child; obj; obj = obj->next, c++)
for (obj = object->child; obj; (void)(obj = obj->next), c++)
{
unsigned char *found = (unsigned char*)cJSONUtils_FindPointerFromObjectTo(obj, target);
if (found)
Expand Down Expand Up @@ -226,7 +226,7 @@ static void cJSONUtils_InplaceDecodePointerString(unsigned char *string)
return;
}

for (; *string; s2++, string++)
for (; *string; (void)s2++, string++)
{
*s2 = (*string != '~')
? (*string)
Expand Down Expand Up @@ -298,7 +298,7 @@ static int cJSONUtils_Compare(cJSON *a, cJSON *b)
/* string mismatch. */
return (strcmp(a->valuestring, b->valuestring) != 0) ? -3 : 0;
case cJSON_Array:
for (a = a->child, b = b->child; a && b; a = a->next, b = b->next)
for ((void)(a = a->child), b = b->child; a && b; (void)(a = a->next), b = b->next)
{
int err = cJSONUtils_Compare(a, b);
if (err)
Expand Down Expand Up @@ -589,7 +589,7 @@ static void cJSONUtils_CompareToPatch(cJSON *patches, const unsigned char *path,
size_t c = 0;
unsigned char *newpath = (unsigned char*)malloc(strlen((const char*)path) + 23); /* Allow space for 64bit int. */
/* generate patches for all array elements that exist in "from" and "to" */
for (c = 0, from = from->child, to = to->child; from && to; from = from->next, to = to->next, c++)
for ((void)(c = 0), (void)(from = from->child), to = to->child; from && to; (void)(from = from->next), (void)(to = to->next), c++)
{
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
Expand All @@ -603,7 +603,7 @@ static void cJSONUtils_CompareToPatch(cJSON *patches, const unsigned char *path,
cJSONUtils_CompareToPatch(patches, newpath, from, to);
}
/* remove leftover elements from 'from' that are not in 'to' */
for (; from; from = from->next, c++)
for (; from; (void)(from = from->next), c++)
{
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
Expand All @@ -617,7 +617,7 @@ static void cJSONUtils_CompareToPatch(cJSON *patches, const unsigned char *path,
cJSONUtils_GeneratePatch(patches, (const unsigned char*)"remove", path, newpath, 0);
}
/* add new elements in 'to' that were not in 'from' */
for (; to; to = to->next, c++)
for (; to; (void)(to = to->next), c++)
{
cJSONUtils_GeneratePatch(patches, (const unsigned char*)"add", path, (const unsigned char*)"-", to);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
add_library(unity unity/src/unity.c)

if(ENABLE_CJSON_TEST)

# Disable -Werror for Unity
list(FIND custom_compiler_flags "-Werror" werror_found)
if (werror_found)
target_compile_options(unity PRIVATE "-Wno-error")
endif()

#copy test files
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/inputs")
file(GLOB test_files "inputs/*")
Expand Down
2 changes: 1 addition & 1 deletion tests/parse_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void parse_array_should_parse_arrays_with_multiple_elements(void)
i = 0;
(i < (sizeof(expected_types)/sizeof(int)))
&& (node != NULL);
i++, node = node->next)
(void)i++, node = node->next)
{
TEST_ASSERT_BITS(0xFF, expected_types[i], node->type);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/parse_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void parse_object_should_parse_objects_with_multiple_elements(void)
i = 0;
(i < (sizeof(expected_types)/sizeof(int)))
&& (node != NULL);
i++, node = node->next)
(void)i++, node = node->next)
{
assert_is_child(node, expected_names[i], expected_types[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ Example:

main()
{
if (TEST_PROTECT() == 0)
if (TEST_PROTECT())
{
MyTest();
}
}

If MyTest calls `TEST_ABORT`, program control will immediately return to `TEST_PROTECT` with a non-zero return value.
If MyTest calls `TEST_ABORT`, program control will immediately return to `TEST_PROTECT` with a return value of zero.


Unity Assertion Summary
Expand Down
35 changes: 34 additions & 1 deletion tests/unity/auto/parseOutput.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ def testPassed(array)
@arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\"/>"
end
end

# Test was flagged as having passed so format the output.
# This is using the Unity fixture output and not the original Unity output.
def testPassedUnityFixture(array)
testSuite = array[0].sub("TEST(", "")
testSuite = testSuite.sub(",", "")
testName = array[1].sub(")", "")
if @xmlOut == true
@arrayList.push " <testcase classname=\"" + testSuite + "\" name=\"" + testName + "\"/>"
end
end

# Test was flagged as being ingored so format the output
def testIgnored(array)
Expand All @@ -73,6 +84,14 @@ def testIgnored(array)
reason = array[lastItem].chomp
testSuiteVerify(array[@className])
printf "%-40s IGNORED\n", testName

if testName.start_with? "TEST("
array2 = testName.split(" ")
@testSuite = array2[0].sub("TEST(", "")
@testSuite = @testSuite.sub(",", "")
testName = array2[1].sub(")", "")
end

if @xmlOut == true
@arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
@arrayList.push " <skipped type=\"TEST IGNORED\"> " + reason + " </skipped>"
Expand All @@ -87,6 +106,14 @@ def testFailed(array)
reason = array[lastItem].chomp + " at line: " + array[lastItem - 3]
testSuiteVerify(array[@className])
printf "%-40s FAILED\n", testName

if testName.start_with? "TEST("
array2 = testName.split(" ")
@testSuite = array2[0].sub("TEST(", "")
@testSuite = @testSuite.sub(",", "")
testName = array2[1].sub(")", "")
end

if @xmlOut == true
@arrayList.push " <testcase classname=\"" + @testSuite + "\" name=\"" + testName + "\">"
@arrayList.push " <failure type=\"ASSERT FAILED\"> " + reason + " </failure>"
Expand Down Expand Up @@ -138,7 +165,7 @@ def process(name)
lineSize = lineArray.size
# If we were able to split the line then we can look to see if any of our target words
# were found. Case is important.
if lineSize >= 4
if ((lineSize >= 4) || (line.start_with? "TEST("))
# Determine if this test passed
if line.include? ":PASS"
testPassed(lineArray)
Expand All @@ -149,6 +176,12 @@ def process(name)
elsif line.include? ":IGNORE:"
testIgnored(lineArray)
testIgnore += 1
elsif line.start_with? "TEST("
if line.include? " PASS"
lineArray = line.split(" ")
testPassedUnityFixture(lineArray)
testPass += 1
end
# If none of the keywords are found there are no more tests for this suite so clear
# the test flag
else
Expand Down
2 changes: 1 addition & 1 deletion tests/unity/src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print)
while (nibbles > 0)
{
nibbles--;
nibble = (int)(number >> (nibbles * 4)) & 0x0F;
nibble = (number >> (nibbles * 4)) & 0x0F;
if (nibble <= 9)
{
UNITY_OUTPUT_CHAR((char)('0' + nibble));
Expand Down