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

Suppress compiler warning when compiling common/url.c - url_decode with MSVC #248

Open
vjardin opened this issue Sep 12, 2019 · 4 comments

Comments

@vjardin
Copy link

vjardin commented Sep 12, 2019

I am not fully familiar yet with all the design of p11-kit, but this code looks strange:

*p = (a - HEX_CHARS_UPPER) << 4;

It is highlighted by Microsoft cl.exe compiler:

p11-kit\common\url.c(85): warning C4244: '=' : conversion de '__int64' en 'unsigned char', perte possible de données

(which means conversiion from __int64 to unsigned char, possible lost of information

the compiler is right because:
const static char HEX_CHARS_UPPER[] = "0123456789ABCDEF";

Please, what's the idea or purpose of this code ? I see there are some unit tests, but it does not cover this case.

@ueno
Copy link
Member

ueno commented Sep 12, 2019

It is the most common path and covered actually: https://coveralls.io/builds/25648864/source?filename=common/url.c

The code is parsing a single byte encoded in hex. Suppose it is %AB. First it looks up the occurrence of A in HEX_CHARS_UPPER and assigns it to a. a - HEX_CHARS_UPPER then means a value of the left nibble (0xA). Do the same for 'B' and finally combine them as a single byte ((0xA << 4) | 0xB).

I think it is a false-positive of the compiler.

@vjardin
Copy link
Author

vjardin commented Sep 17, 2019

You are right. I get the point. I think I have an idea to avoid this compiler warning. I'll provide a patch soon.

@vjardin
Copy link
Author

vjardin commented Sep 30, 2019

I'll send a fix after the pull request #251

@ueno ueno changed the title common/url.c - url_decode Suppress compiler warning when compiling common/url.c - url_decode with MSVC Aug 13, 2020
@winner658
Copy link
Contributor

这个issue完成修复了么,修复在哪里了

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

No branches or pull requests

3 participants