Bug Hunting Session
Bug 42492 - BASIC HEX command on 64-bit systems not returning 16 characters on negative long integer
Summary: BASIC HEX command on 64-bit systems not returning 16 characters on negative ...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.3.4 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Uray M. János
URL:
Whiteboard: target:3.7.0 target:3.6.1
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-01 19:01 UTC by irs
Modified: 2012-12-13 21:20 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
fdo#42492: fixing Basic HEX command (1.35 KB, patch)
2012-07-31 07:01 UTC, Uray M. János
Details

Note You need to log in before you can comment on or make changes to this bug.
Description irs 2011-11-01 19:01:50 UTC
With the 64-bit version of Linux the LibreOffice BASIC HEX command, when performed on a negative LONG integer, returns only the first 15 characters. It is failing to return the least significant nibble, the 16th character. 

See sample code below that was run from LibreOffice Writer 3.3.4 OOO330m19 (Build:401) tag libreoffice-3.3.3.1, Ubuntu package 1:3.3.4-0ubuntu1 on an installation of x86-64bit Ubuntu 11.04 with Linux kernel 2.6.38-12 generic Gnome 2.32.1 

Additionally it can be observed in the sample below, that on 64-bit systems the BASIC HEX command, when performed on negative SHORT integers, will return only 8 characters. Possibly the specifications calls for this and it is the correct length for the return string. If not, then it would appear to be a problem and it should be returning a string of 16 characters.

Thanks and regards,
irs.

Sub SampleCodeOfHexProblemFor64Bit

' Issue 1: The HEX return string of negative long integers is missing the least significant nibble.
' Only the first 15 characters are being returned, instead of a total of 16.

dim longTemp as long

longTemp = -1
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))	'Returns: FFFFFFFFFFFFFFF : 15
	' should be: FFFFFFFFFFFFFFFF : 16

longTemp = - 17
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))	'Returns: FFFFFFFFFFFFFFE : 15
	' should be: FFFFFFFFFFFFFFEF : 16

longTemp = - 32768
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))	'Returns: FFFFFFFFFFFF800 : 15
	'Should be: FFFFFFFFFFFF8000 : 16

longTemp = - 32769
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))	'Returns: FFFFFFFFFFFF7FF : 15
	'should be: FFFFFFFFFFFF7FFF : 16

longTemp = - 32785
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))	'Returns: FFFFFFFFFFFF7FE : 15 
	'should be: FFFFFFFFFFFF7FEF : 16

'===
' Issue 2: The HEX return of negative short integers is 8 hex characters. 
' Possibly this is the way the HEX string is supposed to be returned?
' Maybe on a 64-bit system they should be being returned as 16 hex characters.

dim integerTemp as integer
integerTemp = -1
msgbox HEX(integerTemp) & " : " & Cstr(Len(HEX(integerTemp)) 'Returns: FFFFFFFF : 8
	' On 64-bit system should it return as: FFFFFFFFFFFFFFFF : 16 ?

integerTemp = -17
msgbox HEX(integerTemp) & " : " & Cstr(Len(HEX(integerTemp)) 'Returns: FFFFFFEF : 8
	' On 64-Bit system should it return as FFFFFFFFFFFFFFEF : 16 ?
	
integerTemp = -32768 '<--- Highest possible negative 16-bit signed integer
msgbox HEX(integerTemp) & " : " & Cstr(Len(HEX(integerTemp)) 'Returns: FFFF8000 : 8
	' On 64-Bit system should it return as FFFFFFFFFFFF8000 : 16 ?

end sub
Comment 1 irs 2011-11-01 19:28:57 UTC
Sub SampleCodeOfHexProblemFor64Bit

' Issue 1: The HEX return string of negative long integers is missing  
' the least significant nibble.
' Only the first 15 characters are being returned, instead of a total of 16.

dim longTemp as long

longTemp = -1
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))    
' Returns: FFFFFFFFFFFFFFF : 15
' should be: FFFFFFFFFFFFFFFF : 16

longTemp = - 17
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))
' Returns: FFFFFFFFFFFFFFE : 15
' should be: FFFFFFFFFFFFFFEF : 16

longTemp = - 32768
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))    
' Returns: FFFFFFFFFFFF800 : 15
' Should be: FFFFFFFFFFFF8000 : 16

longTemp = - 32769
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))
' Returns: FFFFFFFFFFFF7FF : 15
' should be: FFFFFFFFFFFF7FFF : 16

longTemp = - 32785
msgbox HEX(longTemp) & " : " & Cstr(Len(HEX(longTemp))    
' Returns: FFFFFFFFFFFF7FE : 15 
' should be: FFFFFFFFFFFF7FEF : 16

'===
' Issue 2: The HEX return of negative short integers is 8 hex characters. 
' Possibly this is the way the HEX string is supposed to be returned?
' Maybe on a 64-bit system they should be being returned as 16 hex characters.

dim integerTemp as integer
integerTemp = -1
msgbox HEX(integerTemp) & " : " & Cstr(Len(HEX(integerTemp)) 
' Returns: FFFFFFFF : 8
' On 64-bit system should it return as: FFFFFFFFFFFFFFFF : 16 ?

integerTemp = -17
msgbox HEX(integerTemp) & " : " & Cstr(Len(HEX(integerTemp)) 
' Returns: FFFFFFEF : 8
' On 64-Bit system should it return as FFFFFFFFFFFFFFEF : 16 ?

integerTemp = -32768 '<--- Highest possible negative 16-bit signed integer
msgbox HEX(integerTemp) & " : " & Cstr(Len(HEX(integerTemp)) 
' Returns: FFFF8000 : 8
' On 64-Bit system should it return as FFFFFFFFFFFF8000 : 16 ?

end sub
Comment 2 sasha.libreoffice 2012-02-06 07:12:26 UTC
If we write this:
longTemp = &HFFFFFFFF
Then basic agree, but when add one F to number, it writes:
Inadmissible value or datatype.
Overflow.

Therefore type Long is 4 bytes long even on 64 bit OS

But prints 15 digits

Experimented in LibO 3.5.0 beta on Fedora 64 bit
Comment 3 Uray M. János 2012-07-31 07:01:03 UTC
Created attachment 64979 [details]
fdo#42492: fixing Basic HEX command

The problem is that actually "integer" is 16-bit and "long" is 32-bit (according to http://help.libreoffice.org/Basic/Using_Variables#Integer_Variables , and according to the source code). The HEX command incorrectly printed 16 (15 because of buffer overflow) and 8 digits. I've corrected this in the patch.
Comment 4 Not Assigned 2012-07-31 13:29:19 UTC
Uray M. Janos committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=556720fcdd419820814164ecafbedb6598b5bb20

fdo#42492: fixing Basic HEX command
Comment 5 Not Assigned 2012-07-31 13:29:37 UTC
Noel Power committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=02a7dfb729799f9e1437a718951566640d0fde02

tweak for commit 8181dddb7bf166be4a00e9280d52f8d7a1741290 fdo#42492
Comment 6 Not Assigned 2012-08-10 19:55:48 UTC
Uray M. Janos committed a patch related to this issue.
It has been pushed to "libreoffice-3-6":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=e370b12af6e2c1e3fc3bf67350541c4e4503f40c&g=libreoffice-3-6

fdo#42492: fixing Basic HEX command


It will be available in LibreOffice 3.6.1.
Comment 7 Not Assigned 2012-08-10 19:56:42 UTC
Noel Power committed a patch related to this issue.
It has been pushed to "libreoffice-3-6":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=b0aac2a42566185dd9809e8ded8231a2162bfcba&g=libreoffice-3-6

tweak for commit 8181dddb7bf166be4a00e9280d52f8d7a1741290 fdo#42492


It will be available in LibreOffice 3.6.1.
Comment 8 irs 2012-12-13 03:27:47 UTC
Uray and Noel, Many thanks for fixing this problem.

I've tried the BASIC Hex command with LibreOffice V3.6.2.2 on Ubuntu, 12.10 32-bit and 64-bit Linux versions, and both function in the same way.

I compared the way Microsoft's VB V6 (SP6) and Office 2003 (with Visual Basic V6.5), and it has the same functionailty.

There is one issue I've observed in that the returned hex string now has lower case characters for "a" through "f".

Previously the returned hex string had upper case characters. The two Microsoft products that I tried also return upper case characters.

I suspect that this could result in potential incompatibility issues when importing MS Office files and running their macros.

As this case is now closed I will proceed with opening another case to report this "lower case characters" issue.
thanks and regards, Ian.
Comment 9 irs 2012-12-13 21:20:17 UTC
Case 58222 has been opened to address: BASIC's HEX Command since V3.6.1 (when bug 42492 fix was applied) now returns lower case "a" to "f" characters.