[MCOL-1132] Unsigned Integer overflow for negative value instead of 0 Created: 2018-01-03  Updated: 2023-10-26  Resolved: 2018-01-03

Status: Closed
Project: MariaDB ColumnStore
Component/s: None
Affects Version/s: None
Fix Version/s: Icebox

Type: Bug Priority: Major
Reporter: Jens Röwekamp (Inactive) Assignee: Andrew Hutchings (Inactive)
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Debian 9



 Description   

Inserting a negative integer through the columnstore API which is mapped to a unsigned integer field results in a positive result instead of 0.

If inserting the same value through SQL it is masked to 0.

Reproducible by changing lines 73 and 92 of dataconvert-int.cpp to:

bulk->setColumn(2, (uint64_t) -1);

and

ASSERT_STREQ(row[2], "0");



 Comments   
Comment by Andrew Hutchings (Inactive) [ 2018-01-03 ]

This is a good point, but is not really a bug, I'll explain why...

When you do "(uint64_t) -1" the C++ compiler converts at compile time to 18446744073709551615. You can see this in the objdump of the binary:

    4a68:	48 c7 c2 ff ff ff ff 	mov    $0xffffffffffffffff,%rdx
    4a6f:	be 02 00 00 00       	mov    $0x2,%esi
    4a74:	48 89 c7             	mov    %rax,%rdi
    4a77:	e8 34 fa ff ff       	callq  44b0 <_ZN6mcsapi21ColumnStoreBulkInsert9setColumnEtmPNS_33columnstore_data_convert_status_tE@plt>

So you are effectively doing in code:

bulk->setColumn(2, (uint64_t) 18446744073709551615);

The value in the double column is set to 18446744073709551615 so this is correct behaviour.

Generated at Thu Feb 08 02:26:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.