Either I'm confused or the gc is

donallen donaldcallen at gmail.com
Fri Oct 23 17:41:48 UTC 2020


On Friday, 23 October 2020 at 14:37:41 UTC, H. S. Teoh wrote:
> On Fri, Oct 23, 2020 at 12:47:11PM +0000, donallen via 
> Digitalmars-d wrote:
>> On Thursday, 22 October 2020 at 21:58:04 UTC, rikki cattermole 
>> wrote:
>> > On 23/10/2020 4:56 AM, donallen wrote:
>> > > ==3854==    by 0x1B7E98: void 
>> > > verifier.main(immutable(char)[][]).walk_account_tree(verifier.main(immutable(char)[][]).Account,
>> > > int) (verifier.d:272)
>> > > ==3854==  Uninitialised value was created by a stack 
>> > > allocation
>> > > ==3854==    at 0x1B77FC: void 
>> > > verifier.main(immutable(char)[][]).walk_account_tree(verifier.main(immutable(char)[][]).Account,
>> > > int) (verifier.d:84)
>> > > ==3854==
>> > > ==3854== Conditional jump or move depends on uninitialised 
>> > > value(s)
> [...]
>
> Hmm. Which lines in your posted code do lines 272 and 84 refer 
> to? Those seem to be the problematic spots, but it's not clear 
> where in the function they are, since your posted code doesn't 
> indicate line numbers.
>
>
> I also noticed this bit of code (which may or may not have 
> anything to
> do with it):
>
>>                 int temp;
>>                 if ((temp = one_row(check_quantities,
>> &get_int).integer_value) > 0)
>>                 {
>>                     writeln(account.path,
>>                             " %s is not an asset account but 
>> has splits with
>> non-zero quantities. These will be fixed.");
>> 
>>                     bind_text(fix_quantities, 1, account.guid);
>>                     run_dm_stmt(fix_quantities, &reset_stmt);
>>                 }
>
> The value of `temp` is not used after assignment. This is a 
> rather odd way of writing it.  What's the reason you didn't 
> just write:
>
> 	if (one_row(...) > 0)
>
> instead?

This code was ported from the original C. In the C code, I 
printf-ed the quantity in the error message and so needed to 
stash it somewhere (temp). When I transformed the code to D, I 
think I hadn't discovered format at that point, so just used 
writeln's ability to print the account.path prepended to the 
fixed text of the message. I forgot to take out the temporary and 
write it as you suggest above. So what you see in my code is a 
vestige of the C that is no longer applicable, but not harmful.

>
>
> [...]
>> MultiType one_row(T)(sqlite3_stmt* stmt, T get_values)
>
> What's the definition of MultiType?

union MultiType
{
     int integer_value;
     sqlite3_int64 long_integer_value;
     double double_value;
     string string_value;
     void* pointer_value;
}

>
>
> [...]
>>     return result; // Need this for compiler happiness -- 
>> can't get here
>
> Note for the future: you could write `assert(0);` here to 
> indicate that it should not be reachable. (It compiles to a 
> single 'hlt' instruction, which will abort if the program 
> somehow reaches it anyway.)

Thanks for the tip, useful if there's D in my future (which there 
will be if you guys can find something wrong with my code rather 
than the system).

>
>
> T




More information about the Digitalmars-d mailing list