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

Check static analyzer log #6

Open
mcrha opened this issue Apr 4, 2022 · 23 comments
Open

Check static analyzer log #6

mcrha opened this issue Apr 4, 2022 · 23 comments

Comments

@mcrha
Copy link
Contributor

mcrha commented Apr 4, 2022

I happen to get to a static analyzers' log, which may contain something useful for you, I hope. It was crated with 0.6.75, which had only the extern_c patch applied on top of the official release.

I do not know the libpst internals, otherwise I'd help with the addressing of the issues. Note the static analyzers have a lot of false positives and they can be (over) pendantic too, thus it can be the log doesn't contain anything useful for you. Note few of the warnings are marked [important].

@pabs3
Copy link
Member

pabs3 commented Apr 5, 2022 via email

@mcrha
Copy link
Contributor Author

mcrha commented Apr 5, 2022

If the extern C patch hasn't been fully merged upstream already, please send a pull request for that.

An interesting thing about this patch is that none of the Fedora branches have it. They use 0.6.76, from which I guess the patch is applied to the libpst in some form.

Does the tool have any of its own checks or does it delegate all checks to the tools mentioned at the end of the report; clang, coverity, cppcheck, gcc, shellcheck, unicontrol.

It's all delegated to those listed tools. I do not know any details about any of those, this is just ran internally as part of a package checking. If you wish, I can re-run the tests manually with any patch (and with any version of the libpst), to see whether any proposed change would help.

pabs3 added a commit that referenced this issue May 9, 2022
Suggested-by: cppcheck
See-also: #6
pabs3 added a commit that referenced this issue May 9, 2022
The DEBUG_WARN has two parameters, so it should have two conversions.

See-also: #6
@pabs3
Copy link
Member

pabs3 commented May 9, 2022

@mcrha I fixed a couple of issues in git main. Now I'm working on correcting all the printf conversion specifiers, especially the ones that should be using PRIx32 type size specs. If you could run the branch through your tool, that would help. There are still more fixes to make, but libpst.c should be done for the DEBUG_* macros.

https://github.com/pabs3/libpst/compare/correct-printf-specifiers

@mcrha
Copy link
Contributor Author

mcrha commented May 9, 2022

I've a hard time to build the branch under Fedora:
https://koji.fedoraproject.org/koji/taskinfo?taskID=86839765

checking whether to build the libpst python interface... yes
./configure: line 26383: syntax error near unexpected token `>'
./configure: line 26383: `    AX_PYTHON_DEVEL(>= '$PYTHON_VERSION')'

but even when I "fix that", there are no m4/ files (as they use to be in the official releases), thus it fails to find these Python and Boost AX macros, then it even fails on missing pyconfig.h.

@mcrha
Copy link
Contributor Author

mcrha commented May 9, 2022

There is also missing content of the man directory (https://github.com/pst-format/libpst/tree/main/man), or it was not built here for some reason. Similarly the *.html files in the doc/ and doc/devel/ and the m4/* files. When I workaround these I can build it and the result is this scan-results.html

@pabs3
Copy link
Member

pabs3 commented May 10, 2022 via email

@pabs3
Copy link
Member

pabs3 commented May 10, 2022 via email

@mcrha
Copy link
Contributor Author

mcrha commented May 10, 2022

Which AX_PYTHON_DEVEL are you using in Fedora?

I had missing the right dependency, I believe. I just wanted to give you the Coverity Scan report quickly, which took me quite a long time at the end, but it was all about me not running the autoreconf properly, I guess. I resorted to several hacks to make it work "as before", without influencing the compilation itself.

@pabs3
Copy link
Member

pabs3 commented May 10, 2022 via email

@pabs3
Copy link
Member

pabs3 commented May 13, 2022

@mcrha I've updated the branch again to fix the remaining printf argument warnings and all the mistakes I could see when auditing all the files for printf arguments.

The only issue I'm not sure about with the printf arguments is that some of the existing calls printf hex of signed integers. That seems like it is not supposed to be possible according to the printf docs. In the patch I changed them to decimal, but that changes the output format. Would it be better to cast signed integers to unsigned before passing to printf?

@mcrha
Copy link
Contributor Author

mcrha commented May 13, 2022

You do not need to mention me, I'm still here :)

In the patch I changed them to decimal, but that changes the output format. Would it be better to cast signed integers to unsigned before passing to printf?

Hmm, changing output format can be problematic, if it's used by the callers. It depends on the actual use case, aka where it was done. I prefer to be on a safe side, thus I'd rather cast the value (an interesting thing would be to see what it did before the change, when the highest bit was set).

@pabs3
Copy link
Member

pabs3 commented May 13, 2022 via email

@mcrha
Copy link
Contributor Author

mcrha commented May 13, 2022

Ah. Not everyone has notifications turned on for threads they participate in, so I usually @ mention people when needed.

I see. In that case do it as you are used to. It's not that critical here like on GitLab, where mentioning someone adds him/her a to-do, which I really do not like, because the to-do should be my list, managed by me, not by everybody.

The log at commit a3c033a is here:
scan-results.html.txt
weird it shows more things than before.

pabs3 added a commit to pabs3/libpst that referenced this issue May 14, 2022
The existing calls often used incorrect specifiers for the argument types.

The PRIx64 style specifiers and z length modifiers for uint64_t style and
size_t integer types are portable between architectures while manual length
modifiers are not.

Drop casts from arguments where a length modifier should be used instead.

Add casts to arguments where needed to change types to what printf expects.

Correct types or signedness of variables where the printf specifier is better.

Switch from printing pointers as integers to printing them as pointers.

Also ensure a space is present before and after PRIx64 style specifiers,
for compatibility with C++11.

Suggested-by: https://github.com/csutils/csmock
See-also: pst-format#6
@pabs3
Copy link
Member

pabs3 commented May 14, 2022

Looks like all the PRINTF_ARGS issues got solved, but the solutions caused other issues in the form of compiler warnings about missing spaces between components of a string literal in C++11. Fixed.

I also went through the patch with a side-by-side coloured diff to ensure that all the changes make sense.

I read that interpreting a signed integer as an unsigned one is equivalent to a cast, so I elected to make that explicit by adding casts.I changed the type of some variables where a signed variable doesn't make sense.

I fixed some other things I missed too.

So I think the printf branch is now done. If you would like to review it too, that would be great.

@mcrha
Copy link
Contributor Author

mcrha commented May 16, 2022

An updated scan-results.html is here. It's at commit 16ca280 .

I also built the package under Fedora Rawhide. Check the x86_64 and i686 build.log files, the 64bit claims 3 warnings, the 32bit 4 warnings (I searched for [-w in the file).

I did not do any real review of the changes, the patch is simply huge and I do not know the internals, variable types and so on. I'm sorry.

pabs3 added a commit to pabs3/libpst that referenced this issue May 3, 2023
The existing calls often used incorrect specifiers for the argument types.

The PRIx64 style specifiers and z length modifiers for uint64_t style and
size_t integer types are portable between architectures while manual length
modifiers are not.

Drop casts from arguments where a length modifier should be used instead.

Add casts to arguments where needed to change types to what printf expects.

Correct types or signedness of variables where the printf specifier is better.

Switch from printing pointers as integers to printing them as pointers.

Also ensure a space is present before and after PRIx64 style specifiers,
for compatibility with C++11.

Suggested-by: https://github.com/csutils/csmock
See-also: pst-format#6
pabs3 added a commit to pabs3/libpst that referenced this issue Aug 14, 2023
The existing calls often used incorrect specifiers for the argument types.

The PRIx64 style specifiers and z length modifiers for uint64_t style and
size_t integer types are portable between architectures while manual length
modifiers are not.

Drop casts from arguments where a length modifier should be used instead.

Add casts to arguments where needed to change types to what printf expects.

Correct types or signedness of variables where the printf specifier is better.

Switch from printing pointers as integers to printing them as pointers.

Also ensure a space is present before and after PRIx64 style specifiers,
for compatibility with C++11.

Suggested-by: https://github.com/csutils/csmock
See-also: pst-format#6
@pabs3
Copy link
Member

pabs3 commented Aug 15, 2023

@mcrha given csmock isn't available in Debian and requires RPM infrastructure anyway, what is the easiest way for me to be able to run it myself so I can iterate through the different issue classes without the extra latency of asking someone else to run it? Can I run it from a Fedora live image on a spare laptop for eg?

pabs3 added a commit that referenced this issue Aug 15, 2023
The existing calls often used incorrect specifiers for the argument types.

The PRIx64 style specifiers and z length modifiers for uint64_t style and
size_t integer types are portable between architectures while manual length
modifiers are not.

Drop casts from arguments where a length modifier should be used instead.

Add casts to arguments where needed to change types to what printf expects.

Correct types or signedness of variables when printf specifier is better.

Switch from printing pointers as integers to printing them as pointers.

Drop a format string macro that was used with two different types.

Also ensure a space is present before and after PRIx64 style specifiers,
which are macros, for readability and compatibility with C++11.

Suggested-by: https://github.com/csutils/csmock
See-also: #6
@pabs3
Copy link
Member

pabs3 commented Aug 15, 2023

I have rechecked, fixed and merged the patch fixing the printf format strings.

@mcrha
Copy link
Contributor Author

mcrha commented Aug 15, 2023

I did not use any public Coverity Scan instance for testing, it's all internal, I'm sorry. Maybe you can add a project into https://scan.coverity.com/ just as libical or evolution-data-server, though I do not know what state these projects are in (the last check seems quite long time ago).

@pabs3
Copy link
Member

pabs3 commented Aug 15, 2023 via email

@mcrha
Copy link
Contributor Author

mcrha commented Aug 16, 2023

Sure, I can help. It's still kinda tricky to make it build from the git snapshot, because the man/ directory has still missing all the man files the Makefile.am references, thus I hacked the build to not enter the man/ directory at all. This had been mentioned above too, even it's not directly related to the static analysers.

Anyway, the build finally succeeded and here is the result:
scan-results.html Change the extension to .html, the GitHub doesn't allow attaching .html files... :-/

@mcrha
Copy link
Contributor Author

mcrha commented Aug 16, 2023

I forgot to mention, the package name contains the date and the commit hash it had been built from. Feel free to ask for more builds, it will be simpler now.

pabs3 added a commit that referenced this issue Aug 20, 2023
Suggested-by: gcc -Wanalyzer
Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit that referenced this issue Aug 20, 2023
The fallthrough is intended but the code is clearer without it.

Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit that referenced this issue Aug 20, 2023
open() returns -1 to indicate an error, the code checked for 0 for errors.

Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit that referenced this issue Aug 20, 2023
pabs3 added a commit that referenced this issue Aug 20, 2023
snprintf takes a char* but the var was a uint8_t, which is unsigned char*.

Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit that referenced this issue Aug 20, 2023
snprintf takes a char* but the var was a uint8_t, which is unsigned char*.

Suggested-by: gcc -Wpointer-sign
Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit that referenced this issue Aug 20, 2023
snprintf takes a char* but the var was a uint8_t, which is unsigned char*.

Suggested-by: gcc -Wpointer-sign
Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit that referenced this issue Aug 20, 2023
The move is more efficient than the copies.

Suggested-by: https://github.com/csutils/csmock
See-also: #6
pabs3 added a commit to pabs3/libpst that referenced this issue Aug 20, 2023
@pabs3
Copy link
Member

pabs3 commented Aug 20, 2023

@mcrha made a bunch of fixes, could you update the scan?

@mcrha
Copy link
Contributor Author

mcrha commented Aug 21, 2023

Sure thing. Here you are.

pabs3 added a commit that referenced this issue Sep 17, 2023
Suggested-by: valgrind
See-also: #6
pabs3 added a commit that referenced this issue Sep 17, 2023
Suggested-by: valgrind
See-also: #6
pabs3 added a commit that referenced this issue Sep 17, 2023
Suggested-by: valgrind
See-also: #6
pabs3 added a commit that referenced this issue Sep 17, 2023
Suggested-by: valgrind
See-also: #6
pabs3 added a commit that referenced this issue Sep 17, 2023
Suggested-by: valgrind
See-also: #6
pabs3 added a commit that referenced this issue Sep 17, 2023
Suggested-by: valgrind
See-also: #6
pabs3 added a commit that referenced this issue Sep 17, 2023
Switch away from using function-scope static variables,
because there is no easy way to free them.

Suggested-by: valgrind
See-also: #6
pabs3 added a commit to pabs3/libpst that referenced this issue Sep 17, 2023
pabs3 added a commit to pabs3/libpst that referenced this issue Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants