Hi LLVM developers,
This is the split patch about Taught the analyzer about Glib API to check Memory-leak for g_malloc_n, g_realloc_n and sort of XXX_n with two arguments APIs.
Please review my patch, thanks a lot!
Regards,
Leslie Zhai
Differential D30771
[analyzer] Teach the MallocChecker about Glib API for two arguments xiangzhai on Mar 8 2017, 7:50 PM. Authored by
Details Hi LLVM developers, This is the split patch about Taught the analyzer about Glib API to check Memory-leak for g_malloc_n, g_realloc_n and sort of XXX_n with two arguments APIs. Please review my patch, thanks a lot! Regards,
Diff Detail
Event TimelineComment Actions Hello, thanks for the patch! It seems that ReallocMemN re-uses a lot of code from the original ReallocMem. Is it possible to re-use rather than copy-paste the code? For example, by moving the common code to a separate function like ReallocMemAux, which is then called from both functions, or turning these two functions into one with an extra boolean paramenter. Comment Actions Hi NoQ, Thanks for your review! As you suggested, I rename ReallocMem to ReallocMemAux with an extra boolean paramenter SuffixWithN, please review it, thanks a lot! Regards,
Comment Actions Hi Artem, Thanks for your review! I updated my patch using if () {} else {} instead of ? : And someone used Arg1ValG so I just keep formation TotalSizeG have not idea what G stands for... Regards, Comment Actions
Nono, that wasn't the point, i have no preference between those. I mean, you can avoid branching completely. See the new inline comment.
Aha, that explains :)
Comment Actions Hi Artem, Thanks for your review!
Sorry for my stupid careless... And I changed TotalSizeG to TotalSize then TotalSize.castAs<DefinedOrUnknownSVal>() as you suggested. For double check, I run the testcase: Clang :: Analysis/gmalloc.c Regards, Comment Actions Hi Leslie, How do you run the tests? You should run all clang (or at least all analyzer) tests when testing the patches, not just select test cases. Comment Actions Hi Anna, Thanks for your correcting! Sorry for my mistake, I use make check-clang-analysis instead of just select test cases. Regards,
Comment Actions Hi Artem, Thanks for your review! I will update my patch tomorrow, good night in my time zone :) Regards, Comment Actions Hi Artem, I updated my patch as you suggested: never using Arg1Val after TotalSize is computed, on all branches. please review it, thanks a lot! Regards,
Comment Actions Hi Daniel, Thanks for your review! I updated my patch as you suggested! Please review it, thanks a lot! but I argue that:
Yes! it is difficult to suitably name variable, function, project, and even my kid :) but calculateBufferSize is not make sense:
I hold the view that I need to respect original developers' code, and it need a Global Patch for Capital variable, just like KDE's Use nullptr everywhere
The same story. Regards, Comment Actions Yay, now that's a lot cleaner! Regarding style, recently we tend to ask for updating the style in the new code, and i don't think the Golden Rule (http://llvm.org/docs/CodingStandards.html#introduction) does much in our case, but i don't have a strong opinion on that. Maybe we could make a checker to make sure all SValBuilder references are called, say, SVB, and all SVal instances have names ending with Val, and have ourselves fix all the issues reported :) But because the analyzer is done by very few people, i don't think this would happen soon, but having the new code stylish is kind of nice anyway. However, the null-check for the argument expression is also a performance issue (the compiler would never guess it's always non-null), so i believe it should definitely be removed. Comment Actions Hi Artem, Thanks for your review! I updated my patch, please review it. Regards, Comment Actions
Yes I was too picky. Please respect the original developers' code.
Comment Actions Hi Daniel, I respect you! the father of cppcheck and KDE's buildbot use cppcheck for example Static Analysis K3B thanks for your great job! Regards,
Comment Actions I don't have further comments except that I would personally rewrite: // Get the value of the size argument. SVal TotalSize = State->getSVal(Arg1, LCtx); if (SuffixWithN) { const Expr *Arg2 = CE->getArg(2); TotalSize = evalMulForBufferSize(C, Arg1, Arg2); } to: // Get the value of the size argument. SVal TotalSize; if (!SuffixWithN) { TotalSize = State->getSVal(Arg1, LCtx); } else { TotalSize = evalMulForBufferSize(C, Arg1, CE->getArg(2)); } Comment Actions you can ignore my comment ... LGTM I don't want to accept this revision. Hopefully NoQ or somebody else can do that. Comment Actions If you have svn write permission then please do it. If you need svn write permission, please see http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access |