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

Avoid array-out-of-bounds when building in sourcedir subdir. #624

Closed
wants to merge 1 commit into from
Closed

Conversation

sgh
Copy link

@sgh sgh commented Aug 4, 2017

The type of errors avoided looks like this.

../src/common.c:2250:9: bemærk: in expansion of macro »ILOG«
ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
^~~~

The type of errors avoided looks like this.

../src/common.c:2250:9: bemærk: in expansion of macro »ILOG«
         ILOG("Ignoring %d bytes of 0x%02x at end of file\n", num_empty, erased_pattern);
         ^~~~
@xor-gate
Copy link
Member

xor-gate commented Aug 9, 2017

I'm unable to accept this PR as-is. I'm not sure what problem you are trying to resolve. An out-of-bound should not be possible. Please provide more information about your compiler and path info.

@sgh
Copy link
Author

sgh commented Aug 9, 2017 via email

@xor-gate
Copy link
Member

xor-gate commented Aug 9, 2017

I have not tested with ninja.
With clang on OS X this produces also a weird error:

jerry@Jerrys-iMac:build > cmake -G "Ninja" ..
-- The C compiler identification is AppleClang 8.1.0.8020042
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- stlink version: 1.4.0-4-g47ce70d
--           Major 1 Minor 4 Patch 0
-- Performing Test C_SUPPORTS_STD_GNU99
-- Performing Test C_SUPPORTS_STD_GNU99 - Success
-- Performing Test C_SUPPORTS_WALL
-- Performing Test C_SUPPORTS_WALL - Success
-- Performing Test C_SUPPORTS_WEXTRA
-- Performing Test C_SUPPORTS_WEXTRA - Success
-- Performing Test C_SUPPORTS_WSHADOW
-- Performing Test C_SUPPORTS_WSHADOW - Success
-- Performing Test C_SUPPORTS_D_FORTIFY_SOURCE_2
-- Performing Test C_SUPPORTS_D_FORTIFY_SOURCE_2 - Success
-- Performing Test C_SUPPORTS_FSTRICT_ALIASING
-- Performing Test C_SUPPORTS_FSTRICT_ALIASING - Success
-- Performing Test C_SUPPORTS_WUNDEF
-- Performing Test C_SUPPORTS_WUNDEF - Success
-- Performing Test C_SUPPORTS_WFORMAT
-- Performing Test C_SUPPORTS_WFORMAT - Success
-- Performing Test C_SUPPORTS_WFORMAT_SECURITY
-- Performing Test C_SUPPORTS_WFORMAT_SECURITY - Success
-- Performing Test C_SUPPORTS_WMAYBE_UNINITIALIZED
-- Performing Test C_SUPPORTS_WMAYBE_UNINITIALIZED - Failed
-- Performing Test C_SUPPORTS_WMISSING_VARIABLE_DECLARATIONS
-- Performing Test C_SUPPORTS_WMISSING_VARIABLE_DECLARATIONS - Success
-- Performing Test C_SUPPORTS_WSHORTEN_64_TO_32
-- Performing Test C_SUPPORTS_WSHORTEN_64_TO_32 - Success
-- Performing Test C_SUPPORTS_WIMPLICIT_FUNCTION_DECLARATION
-- Performing Test C_SUPPORTS_WIMPLICIT_FUNCTION_DECLARATION - Success
-- Performing Test C_SUPPORTS_WREDUNDANT_DECLS
-- Performing Test C_SUPPORTS_WREDUNDANT_DECLS - Success
-- Performing Test C_SUPPORTS_FPIC
-- Performing Test C_SUPPORTS_FPIC - Success
-- Performing Test C_SUPPORTS_O2
-- Performing Test C_SUPPORTS_O2 - Success
-- Performing Test C_SUPPORTS_WERROR
-- Performing Test C_SUPPORTS_WERROR - Success
-- Found Libusb: /usr/local/lib/libusb-1.0.a
-- Looking for sys/mman.h
-- Looking for sys/mman.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Manpage generation disabled
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jerry/files/repos/stlink/build
[1/27] Building C object CMakeFiles/stlink-static.dir/src/sg.c.o
FAILED: CMakeFiles/stlink-static.dir/src/sg.c.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -DCMAKE_SOURCE_DIR_LENGTH=32 -DSTLINK_HAVE_SYS_MMAN_H -DSTLINK_HAVE_UNISTD_H -I/usr/local/include/libusb-1.0 -I../include -Iinclude -I../src/mingw -std=gnu99 -Wall -Wextra -Wshadow -D_FORTIFY_SOURCE=2 -fstrict-aliasing -Wundef -Wformat -Wformat-security -Wmissing-variable-declarations -Wshorten-64-to-32 -Wimplicit-function-declaration -Wredundant-decls -fPIC -O2 -Werror -g -MD -MT CMakeFiles/stlink-static.dir/src/sg.c.o -MF CMakeFiles/stlink-static.dir/src/sg.c.o.d -o CMakeFiles/stlink-static.dir/src/sg.c.o   -c ../src/sg.c
../src/sg.c:128:9: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
        WLOG("%s: receiving failed: %d\n", __func__, ret);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/stlink/logging.h:35:19: note: expanded from macro 'WLOG'
#define WLOG(...) WLOG_HELPER(__VA_ARGS__, "")
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/stlink/logging.h:34:52: note: expanded from macro 'WLOG_HELPER'
#define WLOG_HELPER(format, ...)   ugly_log(UWARN, UGLY_LOG_FILE, format, __VA_ARGS__)
                                                   ^~~~~~~~~~~~~
../include/stlink/logging.h:26:32: note: expanded from macro 'UGLY_LOG_FILE'
#define UGLY_LOG_FILE (__FILE__+CMAKE_SOURCE_DIR_LENGTH)
                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
../src/sg.c:128:9: note: use array indexing to silence this warning
../include/stlink/logging.h:35:19: note: expanded from macro 'WLOG'
#define WLOG(...) WLOG_HELPER(__VA_ARGS__, "")
                  ^
../include/stlink/logging.h:34:52: note: expanded from macro 'WLOG_HELPER'
#define WLOG_HELPER(format, ...)   ugly_log(UWARN, UGLY_LOG_FILE, format, __VA_ARGS__)
                                                   ^
../include/stlink/logging.h:26:32: note: expanded from macro 'UGLY_LOG_FILE'
#define UGLY_LOG_FILE (__FILE__+CMAKE_SOURCE_DIR_LENGTH)
                               ^
../src/sg.c:132:9: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]

Something seems to be really broken with ninja. We need to investigate this more :_(

@xor-gate
Copy link
Member

xor-gate commented Aug 9, 2017

Probably because __FILE__ is a string and the length is an number. Clang has a much more clear error: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]

@sgh
Copy link
Author

sgh commented Aug 9, 2017 via email

@xor-gate
Copy link
Member

Yeah but both GCC and Clang treat it different when building with Ninja. We need to investigate more why this happens.

@sgh
Copy link
Author

sgh commented Aug 11, 2017 via email

@xor-gate
Copy link
Member

Thank you for the PR, but we need to consider a different solution. Further discussion will be proceeded in #628.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang 4.0.0+ can not compile version 1.4.0
3 participants