stlink: Build failure when platform is 32 bit, but stuct stat.st_size is 64 bit.

When host platform is 32 bit (and size_t is 32 bit), but struct stat st_size field is 64 bit build fails:

/usr/bin/cc -DCMAKE_SOURCE_DIR_LENGTH=50 -DSTLINK_HAVE_SYS_MMAN_H -DSTLINK_HAVE_UNISTD_H -Iinclude -Isrc/mingw -O2 -pipe  -fstack-protector -fno-strict-aliasing -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 -Wno-string-plus-int -Wredundant-decls -fPIC -O2 -Werror -O2 -pipe  -fstack-protector -fno-strict-aliasing -MD -MT CMakeFiles/stlink-static.dir/src/common.c.o -MF CMakeFiles/stlink-static.dir/src/common.c.o.d -o CMakeFiles/stlink-static.dir/src/common.c.o   -c src/common.c
src/common.c:1034:41: error: implicit conversion loses integer precision: 'off_t' (aka 'long long') to 'size_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
    mf->base = (uint8_t*) mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
                          ~~~~       ~~~^~~~~~~
src/common.c:1040:18: error: implicit conversion loses integer precision: 'off_t' (aka 'long long') to 'size_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
    mf->len = st.st_size;
            ~ ~~~^~~~~~~
2 errors generated.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@chenguokai: Thx for the feedback. Reopening this then…

@Nightwalker-87 I am afraid that this issue is not resolved in 1.6.0 I am the maintainer of stlink of MacPorts. I just received the same error report on snow leopard. The error log can be found on https://build.macports.org/builders/ports-10.6_i386-builder/builds/10447/steps/install-port/logs/stdio