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

c++20 undefined behavior usage #300

Closed
1 task done
lirik90 opened this issue Aug 11, 2023 · 2 comments · Fixed by #312
Closed
1 task done

c++20 undefined behavior usage #300

lirik90 opened this issue Aug 11, 2023 · 2 comments · Fixed by #312
Labels

Comments

@lirik90
Copy link

lirik90 commented Aug 11, 2023

What happened?

Hi. It's can't be compiled with this command:

g++ -std=c++20 -fsanitize=undefined test.cpp

Problem in line 86 file include/jwt-cpp/base.h

static std::initializer_list<std::string> fill{"%3D", "%3d"};

How To Reproduce?

#include <jwt-cpp/traits/kazuho-picojson/defaults.h>
int main() {
  return 0;
}

Version

0.6.0

What OS are you seeing the problem on?

Linux

What compiler are you seeing the problem on?

GCC

Relevant log output

[kirill@main-pc test]$ g++ -std=c++20 -fsanitize=undefined ~/test.cpp 
In file included from /jwt-cpp/include/jwt-cpp/jwt.h:12,
                 from /jwt-cpp/include/jwt-cpp/traits/kazuho-picojson/traits.h:12,
                 from /jwt-cpp/include/jwt-cpp/traits/kazuho-picojson/defaults.h:4,
                 from /home/kirill/test.cpp:2:
/jwt-cpp/include/jwt-cpp/base.h: In static member function «static const std::initializer_list<std::__cxx11::basic_string<char> >& jwt::alphabet::helper::base64url_percent_encoding::fill()»:
/jwt-cpp/include/jwt-cpp/base.h:86:100: ошибка: «(((const std::__cxx11::basic_string<char>*)(& <temporary>)) != 0)» не есть константное выражение
   86 |                                         static std::initializer_list<std::string> fill{"%3D", "%3d"};
      |

Code of Conduct

  • I agree to follow this project's Code of Conduct
@prince-chrismc
Copy link
Collaborator

Create a test for the undefined sanitizer

@sjanel
Copy link
Contributor

sjanel commented Aug 18, 2023

This is because std::initializer_list is a proxy object that should not be used as a storage (it has been made for one purpose, being used as a parameter). It could be replaced with a standard array.

The issue can be fixed like this

@prince-chrismc prince-chrismc linked a pull request Nov 26, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants