Page 1 of 1

${Ini} and other strings

Posted: Wed Oct 13, 2004 12:28 pm
by Grumpy
While messing with a bazaar search macro, I discovered a glitch of sorts.

Relating to ${Ini[${filename}, ${sectionname}]}, which returns a tokenized list of keys in the ini file section.

"Key 1|Key 2|...|Key n|Key last||"

If you have an ini file with lots of keys (or more long keys), the return string can be corrupt. Apparently (haven't looked at source), the return string is limited to 2k characters (or so), and truncates. This is better than having a buffer overrun, but not ideal.

Problem occurs when you try and tokenize the returned string, if you are looking for the || at the end of the key list, you aren't going to find it. Can we have ${Ini[${filename}, ${sectionname}]} check the return string length and truncate before the limit is reached? Thus not processing all the keys?

A better solution (more flexible) would be to add ${Ini.Count[${filename}, ${sectionname}]}, which would just return the number of keys in that section of the file. This is mostly what people want (so they can create a dynamic array of the correct size to hold all the keys).

As I say, I haven't checked, but other functions returning strings may have similar problems with truncation.

Posted: Wed Oct 13, 2004 3:38 pm
by dont_know_at_all
Strings are limited to 2047 characters.

Posted: Wed Oct 13, 2004 10:34 pm
by Grumpy
Right, but my point is that the return string from $Ini is supposed to be in a standard format, I'd rather have it return:

Key1|Key2|...|Last Key that will fit in the 2047 alloted and still leave 2 chars for||

than:

Key1|Key2|...|Last Key that will fit in the 2047 alloted and still leave 2 chars for|Key that won't quite fit

without the promised || at the end of the String.

I'm not worried about the limit on string length, I'm concerned about the corrupted return string.

Adding ${Ini.Count[]) function (returns an int with number of keys in file or in section) would also be very nice.