Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.0.0a1

Bug #20119 PHP warning: invalid argument to str_repeat() in SVN blame report with -s
Submitted: 2013-11-05 14:32 UTC Modified: 2013-11-25 01:14 UTC
From: happydog Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.4.7)
PHP Version: Irrelevant OS: N/A
Roadmaps: (Not assigned)    
Subscription  


 [2013-11-05 14:32 UTC] happydog (Mark Clements)
Description: ------------ Using the --report=svnblame argument will throw PHP errors when the -s switch is used, if the Sniff name is longer than 55 characters. str_repeat(): Second argument has to be greater than or equal to 0 in ~/CodeSniffer/Reports/VersionControl.php on line 172 This occurs because the second argument that is being passed in to str_repeat() is calculated by subtracting from $width argument and, in some cases, this can result in a value that is <= zero. At the start of the function the code makes sure that $width is >= 70, which means that most of the other uses of str_repeat() won't suffer from this problem. They either use $width or $width minus a constant value, and so will always be > 0. On lines 154-157 the subtractions are based on variable content, but they should still not cause problems due to the known maximum length of the strings. The only issue where they might is if there are more than 99999 errors (5 digits) for a single author, or if an author's name is longer than 46 characters, both of which are unlikely enough to not be worth checking for. Similarly, line 171 restricts the count-per-source to 9999 (4 digits), but again this is unlikely to be hit (or is it?). However, on line 172, there is maximum width for a Sniff's source string of 55 characters, which is trivial to hit. For example: Squiz.ControlStructures.LowercaseDeclarationSniff.FoundUppercase (64 characters). Expected result: ---------------- No PHP error occurs. The layout is adjusted (either it is wrapped, or the width limit is exceeded - ideally the former) when the sniff name is too long. Actual result: -------------- PHP errors and layout breakage!

Comments

 [2013-11-25 01:14 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
Committed fix to github repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/2bb00bc0e298b5dce29eb079e 97f2ce1516e01db Should be no more layout breakage :)
 [2014-02-15 01:55 UTC] happydog (Mark Clements)
Great work - thank you!