Skip to content

Compiling with Clang results in many errors w.r.t "unsafe buffer access" #791

@RossSmyth

Description

@RossSmyth

Hello again,

I am once again attempting to run the tests. I have found that the Makefile in the tests directory doesn't use gcc-specific flags. But when you use Clang, it does something very funny:

Unity/test/Makefile

Lines 11 to 15 in b9d897b

ifeq ($(findstring clang, $(CC)), clang)
E = -Weverything
CFLAGS += $E -Wno-unknown-warning-option -Wno-missing-prototypes
CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn
endif

On line 12, that -Weverything, combined with the -Werror

CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror

Means that Clang emits many unsafe-buffer-usage errors, which are not fixable in C I believe.

unity-test> ../src/unity.c:145:13: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>   145 |             pch++;
unity-test>       |             ^~~
unity-test> ../src/unity.c:182:13: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>   182 |             pch++;
unity-test>       |             ^~~
unity-test> ../src/unity.c:450:13: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>   450 |             buf[digits++] = (char)('0' + n % 10);
unity-test>       |             ^~~
unity-test> ../src/unity.c:461:31: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>   461 |             UNITY_OUTPUT_CHAR(buf[--digits]);
unity-test>       |                               ^~~
unity-test> ../src/unity.c:482:17: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>   482 |                 buf[digits++] = (char)('0' + exponent % 10);
unity-test>       |                 ^~~
unity-test> ../src/unity.c:487:35: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>   487 |                 UNITY_OUTPUT_CHAR(buf[--digits]);
unity-test>       |                                   ^~~
unity-test> ../src/unity.c:889:45: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>   889 |             expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment);
unity-test>       |                                             ^~~~~~~~~~~~~~~~~~~~~
unity-test> ../src/unity.c:891:39: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>   891 |         actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment);
unity-test>       |                                       ^~~~~~~~~~~~~~~~~~~
unity-test> ../src/unity.c:1006:13: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>  1006 |             ptr_expected++;
unity-test>       |             ^~~~~~~~~~~~
unity-test> ../src/unity.c:1008:9: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>  1008 |         ptr_actual++;
unity-test>       |         ^~~~~~~~~~
unity-test> ../src/unity.c:1134:20: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>  1134 |         UnityPrint(trait_names[trait_index]);
unity-test>       |                    ^~~~~~~~~~~
unity-test> ../src/unity.c:1234:13: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>  1234 |             ptr_expected++;
unity-test>       |             ^~~~~~~~~~~~
unity-test> ../src/unity.c:1236:9: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>  1236 |         ptr_actual++;
unity-test>       |         ^~~~~~~~~~
unity-test> ../src/unity.c:1361:20: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>  1361 |         UnityPrint(trait_names[trait_index]);
unity-test>       |                    ^~~~~~~~~~~
unity-test> ../src/unity.c:1584:45: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>  1584 |             expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment);
unity-test>       |                                             ^~~~~~~~~~~~~~~~~~~~~
unity-test> ../src/unity.c:1586:39: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage]
unity-test>  1586 |         actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment);
unity-test>       |                                       ^~~~~~~~~~~~~~~~~~~
unity-test> ../src/unity.c:1603:21: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>  1603 |         for (i = 0; expected[i] || actual[i]; i++)
unity-test>       |                     ^~~~~~~~
unity-test> ../src/unity.c:1603:36: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>  1603 |         for (i = 0; expected[i] || actual[i]; i++)
unity-test>       |                                    ^~~~~~
unity-test> ../src/unity.c:1605:17: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>  1605 |             if (expected[i] != actual[i])
unity-test>       |                 ^~~~~~~~
unity-test> fatal error: too many errors emitted, stopping now [-ferror-limit=]
unity-test> 20 errors generated.
unity-test> In file included from tests/test_unity_arrays.c:10:
unity-test> tests/self_assessment_utils.h:89:5: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>    89 |     putcharSpyBuffer[indexSpyBuffer] = '\0';
unity-test>       |     ^~~~~~~~~~~~~~~~
unity-test> tests/self_assessment_utils.h:102:13: error: unsafe buffer access [-Werror,-Wunsafe-buffer-usage]
unity-test>   102 |             putcharSpyBuffer[indexSpyBuffer++] = (char)c;
unity-test>       |             ^~~~~~~~~~~~~~~~
unity-test> 2 errors generated.
unity-test> make: *** [Makefile:108: test] Error 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions