agateau at kde.org
Sat Sep 4 23:10:41 BST 2010
On 02/09/2010 22:15, Thomas Lübking wrote:
> This is a way to access (in this case) the last char of the previous element
> (to eg. replace '\0' with ' ') but actually the particular example looks buggy
> to me, since "wordlist[-1]" is NOT part of "wordlist[max_wordlist]" (which
> starts at wordlist with the first char of the first string.
wordlist is an array of char*. Each char* can point to arbitrary
addresses, not necessarily to the beginning of strings. It really
depends on what fill_words() does. If it initializes wordlist pointers
to point to the beginning of a word in a large string, then
wordlist[-1] may be safe:
If for example wordlist = large_string + 3, then wordlist is
the third character of large_string and wordlist[-1] is the second
character. But of course if wordlist = large_string, then
wordlist[-1] is out of large_string and you are likely to experience
> -> the loop should start at 1, run to words ("<=", or not, depends on what'S
> intended) and access "i-1" in the second position.
> So if it's not somehow guaranteed that there's NOT sth. usefull in this memory
> portion, you get a mem corruption (i think, but maybe this is just beyond no
> me ;-)
> Am Thursday 02 September 2010 schrieb Jaime:
>> I do not know what this methods do,
>> They use a [-1] array index, perhaps to do pointer arithmetic?, but
>> I do not know, it is the first time I see negative indexes in C++
>> They are in kdebase/runtime/kioslave/man/man2html.cpp
>> lines 2845, 3166, 3661, 3693, 3732, 3791, 4067 and 4163.
>> Here you have an extract:of the first case...
>> char *wordlist[max_wordlist];
>> fill_words(c, wordlist, &words, true, &c);
>> for (int i=0; i<words; i++)
>> if ((mode) || (inFMode))
>> out_html(" ");
>> wordlist[i][-1]=' '; <---------------- The unknown thing for
>> me out_html( set_font( (i&1) ? font2 : font1 ) );
>> Best Regards.
More information about the kde-core-devel