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

Fix warnings from cross-compiling with x86_64-w64-mingw32-gcc-posix #1534

Merged
merged 4 commits into from
Aug 31, 2023
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
2 changes: 1 addition & 1 deletion src/lib/OpenEXRCore/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ default_compress_chunk (exr_encode_pipeline_t* encode)
return pctxt->print_error (
pctxt,
rv,
"error allocating buffer %lu",
"error allocating buffer %zu",
exr_compress_max_buffer_size (encode->packed_bytes));
//return rv;

Expand Down
5 changes: 5 additions & 0 deletions src/lib/OpenEXRCore/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,18 @@ exr_attr_string_set_with_length (
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4996)
#elif __MSVCRT__ && __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif
if (d)
strncpy (sstr, d, (size_t) len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the MSVC warning go away if the str[len]='\0' line is copied immediately after the strncpy? I wonder if the compiler is smart enough to see that.

Copy link

@kmilos kmilos Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, __MSVCRT__ seems to be defined even in more modern/compliant UCRT environments like UCRT64 and CLANG64, where I didn't see this warning before... Perhaps this should be checking for && !defined(_UCRT) in addition?

This is from my _mingw.h:

#if !defined(_UCRT) && ((__MSVCRT_VERSION__ >= 0x1400) || (__MSVCRT_VERSION__ >= 0xE00 && __MSVCRT_VERSION__ < 0x1000))
/* Allow both 0x1400 and 0xE00 to identify UCRT */
#define _UCRT
#endif
  • On UCRT64 and CLANG64 (using UCRT), __MSVCRT_VERSION__ is 0xE00 so _UCRT is defined.
  • On recent MINGW64 (using MSVCRT), __MSVCRT_VERSION__ is 0x700, so it is not defined.
  • On older Debian/Ubuntu mingw cross toolchains targeting MSVCRT, either the statement is not in the old _mingw.h so _UCRT is not defined anyway, or __MSVCRT_VERSION__ is also at a lower version.

else
memset (sstr, 0, (size_t) len);
#ifdef _MSC_VER
# pragma warning(pop)
#elif __MSVCRT__ && __GNUC__
#pragma GCC diagnostic pop
#endif
}
sstr[len] = '\0';
Expand Down