Bug in Matt Mullenweg’s “Hello Dolly”
I was looking through the source code of Matt Mullenweg’s WordPress plugin, Hello Dolly, which is shipped with the latest WordPress releases. It contains a minor bug on line 44:
$chosen = wptexturize( $lyrics[ mt_rand(0, count($lyrics) ) ] );
The range in the mt_rand() is too large. Suppose there is only one line, then mt_rand()’s range will be 0 to 1 — that’s one too much, since only element 0 exists. When this bug occurs, no text will be displayed. The risk for it to occur in the standard Hello Dolly plugin is 1 in 29, which is the number of lines plus one (the 0).
The bug could be fixed easily by changing count($lyrics) to count($lyrics) - 1.

[...] As you might expect, I’m not the first one to customize the “Hello Dolly” plugin. Also, I employed this little fix so you won’t get a blank line 1/6 of the time. Hello Ranganathan [...]
Pingback by See Also… » Hello Ranganathan — February 7, 2008 @ 4:54 pm