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

Create a check that warns about using %p printf specifier #43453

Open
LegalizeAdulthood opened this issue Nov 21, 2019 · 7 comments · May be fixed by #75472
Open

Create a check that warns about using %p printf specifier #43453

LegalizeAdulthood opened this issue Nov 21, 2019 · 7 comments · May be fixed by #75472
Labels
bugzilla Issues migrated from bugzilla clang:static analyzer enhancement Improving things as opposed to bug fixing, e.g. new or missing feature good first issue https://github.com/llvm/llvm-project/contribute

Comments

@LegalizeAdulthood
Copy link
Contributor

Bugzilla Link 44108
Version unspecified
OS Windows NT

Extended Description

Recently I ran into some surprising behavior surrounding the use of %p in a printf call. On Windows %p with a nullptr prints zeros, but on Linux %p with a nullptr prints "(nil)". This is surprising, but conforming to the standard which states (roughly) that the result of %p is implementation dependent.

Create a check that warns about the potential non-portable output when using %p in a printf or scanf specifier.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@LegalizeAdulthood LegalizeAdulthood added enhancement Improving things as opposed to bug fixing, e.g. new or missing feature good first issue https://github.com/llvm/llvm-project/contribute labels Jan 9, 2022
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2022

@llvm/issue-subscribers-good-first-issue

@richmanon
Copy link

I have reproduce the issue. Check on windows and linux with the compiler clang and gcc.
The testcase was i written was
#include<stdio.h>
int main()
{
int *pointer=NULL;
printf("%p\n",pointer);
return 0;
}
On windows output was 0000000000000000
On linux output was (nil)

@tensor-ninja
Copy link

tensor-ninja commented Nov 24, 2022

Myself and @Delta456 @aafeke are taking on this issue

@tensor-ninja
Copy link

Submitted patch for review https://reviews.llvm.org/D139604

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2022

@llvm/issue-subscribers-clang-static-analyzer

@whisperity whisperity added the awaiting-review Has pending Phabricator review label Dec 11, 2022
@steakhal steakhal removed the awaiting-review Has pending Phabricator review label Dec 17, 2022
@aabhinavg
Copy link
Member

On mac i used the command

<main][~/git_repo_for_learning/llvm-project/test]$ ../build/bin/scan-build -enable-checker optin.portability ../build/bin/clang 
-g eg.cpp 
scan-build: Using '/Users//git_repo_for_learning/llvm-project/build/bin/clang-17' for static analysis
scan-build: Analysis run complete.
scan-build: Removing directory '/var/folders/2h/_s0drn1j2j9cd4v00hht7k440000gn/T/scan-build-2023-02-05-205217-54968-1' because it contains no reports.
scan-build: No bugs found.>. 

I got no error

clang version 17.0.0 (https://github.com/llvm/llvm-project 8bb54da)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Users/git_repo_for_learning/llvm-project/test/../build/bin

Code for the eg.cpp

#include <stdio.h>
#include <stdlib.h>

int main() {
int *p = nullptr;
printf("%p", p);
}

@tensor-ninja
Copy link

Hi @aabhinavg. That is because the my commit was not accepted. I have not had the time to go back and fix the requests needed to land the patch due to school.

@wenpen wenpen linked a pull request Dec 14, 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
bugzilla Issues migrated from bugzilla clang:static analyzer enhancement Improving things as opposed to bug fixing, e.g. new or missing feature good first issue https://github.com/llvm/llvm-project/contribute
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants