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 compilation error with armv7, x86 #2660

Merged
merged 1 commit into from
Aug 7, 2020
Merged

Fix compilation error with armv7, x86 #2660

merged 1 commit into from
Aug 7, 2020

Conversation

lmarz
Copy link
Contributor

@lmarz lmarz commented Aug 6, 2020

Description

Fixes a compilation error, that appears on alpine linux.

 /builds/lmarz/aports/testing/openimageio/src/oiio-Release-2.1.18.0/src/libOpenImageIO/exif.cpp: In function 'void OpenImageIO_v2_1::read_exif_tag(OpenImageIO_v2_1::ImageSpec&, const TIFFDirEntry*, OpenImageIO_v2_1::cspan<unsigned char>, bool, int, std::set<unsigned int>&, const OpenImageIO_v2_1::pvt::TagMap&)':
 /builds/lmarz/aports/testing/openimageio/src/oiio-Release-2.1.18.0/src/libOpenImageIO/exif.cpp:789:20: error: comparison of integer expressions of different signedness: 'unsigned int' and 'OpenImageIO_v2_1::span<const unsigned char, -1>::index_type' {aka 'int'} [-Werror=sign-compare]
   789 |         if (offset >= buf.size()) {
       |

Checklist:

  • I have read the contribution guidelines.
  • If this is more extensive than a small change to existing code, I
    have previously submitted a Contributor License Agreement
    (individual, and if there is any way my
    employers might think my programming belongs to them, then also
    corporate).
  • I have updated the documentation, if applicable.
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • My code follows the prevailing code style of this project.

@hobbes1069
Copy link
Contributor

Interesting, it hasn't shown up in the Fedora armv7 builds.

src/libOpenImageIO/exif.cpp Outdated Show resolved Hide resolved
@lgritz
Copy link
Collaborator

lgritz commented Aug 6, 2020

Wait a minute, the warning you quoted was about line 789, but your edit is to line 786. Did you change the wrong thing?

@lmarz
Copy link
Contributor Author

lmarz commented Aug 6, 2020

I didn't. Alpine Linux is a bit ... weird. For instance, it uses musl libc instead of the GNU libc library. It quite often happens, that the compiler outputs some weird error messages. This error only appears on 2 architectures, the others are fine. It isn't even specifically arch related.
The error appears a few lines below my change. The compiler says that it's comparing an unsigned int against a signed int (i dont know why this is an error). So I simply changed the offset from unsigned int to int, which eliminates the error and doesn't produce a warning, so I guess it's fine.

@lgritz
Copy link
Collaborator

lgritz commented Aug 6, 2020

The error appears a few lines below my change. The compiler says that it's comparing an unsigned int against a signed int (i dont know why this is an error). So I simply changed the offset from unsigned int to int, which eliminates the error and doesn't produce a warning, so I guess it's fine.

Aah, no, that will just cause other warnings, maybe for people with different compiler versions.

I think the correct fix is to change

    if (offset >= buf.size()) {

to

    if (offset >= size_t(buf.size())) {

I understand why it's happening. It's because buf is a cspan, and its size() returns a signed value, because at the time I made our span class, the draft of C++20's span had its size returning a signed value, but it has since been changed to unsigned, much like the other STL types. We'll do this eventually, too, but it's a compatibility change, so I'm waiting until the kind of release where I'm allowed to introduce potential backwards incompatibilities.

Fixes a compilation error, that appears on alpine linux.
 /builds/lmarz/aports/testing/openimageio/src/oiio-Release-2.1.18.0/src/libOpenImageIO/exif.cpp: In function 'void OpenImageIO_v2_1::read_exif_tag(OpenImageIO_v2_1::ImageSpec&, const TIFFDirEntry*, OpenImageIO_v2_1::cspan<unsigned char>, bool, int, std::set<unsigned int>&, const OpenImageIO_v2_1::pvt::TagMap&)':
 /builds/lmarz/aports/testing/openimageio/src/oiio-Release-2.1.18.0/src/libOpenImageIO/exif.cpp:789:20: error: comparison of integer expressions of different signedness: 'unsigned int' and 'OpenImageIO_v2_1::span<const unsigned char, -1>::index_type' {aka 'int'} [-Werror=sign-compare]
   789 |         if (offset >= buf.size()) {
       |
@lgritz lgritz merged commit af796c9 into AcademySoftwareFoundation:master Aug 7, 2020
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request Aug 29, 2020
Fixes a compilation error, that appears on alpine linux.
 /builds/lmarz/aports/testing/openimageio/src/oiio-Release-2.1.18.0/src/libOpenImageIO/exif.cpp: In function 'void OpenImageIO_v2_1::read_exif_tag(OpenImageIO_v2_1::ImageSpec&, const TIFFDirEntry*, OpenImageIO_v2_1::cspan<unsigned char>, bool, int, std::set<unsigned int>&, const OpenImageIO_v2_1::pvt::TagMap&)':
 /builds/lmarz/aports/testing/openimageio/src/oiio-Release-2.1.18.0/src/libOpenImageIO/exif.cpp:789:20: error: comparison of integer expressions of different signedness: 'unsigned int' and 'OpenImageIO_v2_1::span<const unsigned char, -1>::index_type' {aka 'int'} [-Werror=sign-compare]
   789 |         if (offset >= buf.size()) {
       |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants