Skip to content

Conversation

@postscript-dev
Copy link
Collaborator

RETURN VALUE On success, iconv_open() returns a freshly allocated conversion descriptor. On failure, it returns (iconv_t) -1 and sets errno to indicate the error. 
  • Add new exception when failing to change the text encoding of an Exif comment

Bug is on the main branch and does not affect exiv2 0.27.5.

@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #2403 (7d69936) into main (dc5dc0d) will increase coverage by 0.18%.
The diff coverage is 75.00%.

@@ Coverage Diff @@ ## main #2403 +/- ## ========================================== + Coverage 64.28% 64.46% +0.18%  ========================================== Files 119 119 Lines 21135 21139 +4 Branches 10430 10435 +5 ========================================== + Hits 13586 13627 +41  + Misses 5400 5353 -47  - Partials 2149 2159 +10 
Impacted Files Coverage Δ
include/exiv2/error.hpp 50.00% <ø> (ø)
src/error.cpp 83.60% <ø> (ø)
src/convert.cpp 51.55% <50.00%> (+0.15%) ⬆️
src/value.cpp 72.59% <100.00%> (+0.40%) ⬆️
app/exiv2.cpp 63.43% <0.00%> (+0.89%) ⬆️
app/actions.cpp 67.18% <0.00%> (+2.20%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

- Fix failure condition for `iconv_open()` - Add new exception when failing to change the text encoding of an Exif comment
Copy link
Collaborator

@piponazo piponazo left a comment

Choose a reason for hiding this comment

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

Changes look good to me. Thanks for the additional error checking!

iconv_t cd;
cd = iconv_open(to, from);
if (!cd) {
if (cd == (iconv_t)(-1)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[suggestion] could you define and assign the cd in the same line? Furthermore, is it really needed the cast to iconv_t if we already know that the variable cd is of that type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

musl libc (and most others) have it as
typedef void *iconv_t;

uclibc-ng has it as
typedef long iconv_t;

cast is needed if it's a pointer I think.

This does trigger a clang-tidy check that it's a C cast.

I wonder if there's a C++ way to do this...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@neheb

musl libc (and most others) have it as
typedef void *iconv_t;

uclibc-ng has it as
typedef long iconv_t;

Thanks for letting me know, I wasn't aware of the different definitions. As for a C++ solution, would using std::is_pointer_v help?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No i mean you can't use static_cast or reinterpret_cast as it would fail with void* and long respectively.

if std::is_pointer_v<cd> ? reinterpret_cast<iconv_t>(-1) : static_cast<iconv_t>(-1)) 

is quite verbose.

if (iconv_t(-1)) 

is an alternative but newer clang-tidy warns on that as well.

@postscript-dev postscript-dev marked this pull request as ready for review November 1, 2022 13:33
@postscript-dev postscript-dev merged commit 1f364be into Exiv2:main Nov 1, 2022
@postscript-dev postscript-dev deleted the fix_iconv_seg_fault branch November 1, 2022 15:01
@postscript-dev
Copy link
Collaborator Author

@neheb

musl libc (and most others) have it as
typedef void *iconv_t;

uclibc-ng has it as
typedef long iconv_t;

cast is needed if it's a pointer I think.

This does trigger a clang-tidy check that it's a C cast.
I wonder if there's a C++ way to do this...

While looking at one of your current PRs, I was reminded of this discussion. As we are about to release a new version based on the main branch, are changes needed?

@neheb
Copy link
Collaborator

neheb commented Feb 7, 2023

Not really. The clang-tidy check is just stylistic.

@postscript-dev
Copy link
Collaborator Author

@neheb

Not really. The clang-tidy check is just stylistic.

Thanks for checking, I was wondering about this but was pushed for time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants