alliedmodders/amxmodx — pull request #2 by dvander (2014-02-10 07:47:54+00:00)
Title: Add new variants of strbreak, which is too broken to use.

Long story short, strbreak() is incredibly broken. The new tests try to document its behavior, but basically, it contributes leading whitespace toward the budget of the left-hand buffer. If the amount of leading whitespace is greater than the buffer size, it will infinite loop. This patch clamps down on that while still making sure the output string is at least made empty.

After discovering how sketchy strbreak() is, I threw together a new native, argparse(), which is an improved BreakString() from SourceMod. SourceMod's BreakString suffers from two problems: one, it does not codify what an argument is very well. Second, it requires two position variables to use: the index it returns is relative to the start of the string, and if you use a slice, the position will be wrong unless you use another variable as an accumulator.

argparse() fixes this by specifying precisely how arguments are broken (it is designed to match bash), and taking the position in as a parameter instead of requiring slices. I also added an argbreak() which is a stock that simulates strbreak() via argparse().