Solved [D#83000] SalStrRightX and negative lengths - SalStrRightX_bug.zip

forum.gupta.bugreport (2005-2010)
Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3390
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

[D#83000] SalStrRightX and negative lengths - SalStrRightX_bug.zip

Post by Dave Rabelink » 02 Apr 2005, 00:51

I discovered this bug with the functions

SalStrRightX
SalStrRight

When (mistakenly) a negative length is supplied to these functions,
the resulting string will be corrupted !!!

Here a small example :

Set sData = "0123456789"
Set sRight = SalStrRightX( sData, -5 )

sData has 10 characters, the string length is 10 and it's buffer
length is 11 (last character is the terminating \0 value). This is
normal !

It is expected that sRight will be an empty string with its buffer
length set to 1. I know it is not sound to give negative lengths to
this function, but mistakes are easily made.

Now when we determine the size of the string, it is 0 (expected)
But it's buffer length is 11 !!!

It does not matter which negative number is used, it is always 11
in this case.

Even worse, when the sRight function is used in further concatenations
it will give unwanted results.

Like

Set sConcat = "This is the " || sRight || " string in a concatenation"

The value of sConcat will be :

"This is the "

Code like this :

if sRight
Call something( )

is evaluated to TRUE, so it executes something( )

if sRight = STRING_Null
Call something( )

is evaluated to TRUE, so it executes something( )
This is expected !

When using the SalStrLeft and SalStrMid functions with negative
lengths, the resulting string will be as expected. An empty string
with buffer length 1.

I tested it in TD 1.5.1 ptf 6 and TD 3.1 ptf 3 and this behaviour is
present in those two versions.

An example is included, so see for yourself.

I discovered this while porting from 1.5.1 to 3.1.
We use the Object Compiler in 1.5.1 for special functionality. The
SalStrRight with negative length occurred in the code but there it
behaves like expected. In 3.1 we can not use the OC due to bugs and
run the same code in native SAL and there it fails.
It results in TD 3.1 in instable applications and for us in sudden
crashes on unexpected locations.

I will log-a-bug this !

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3390
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: [D#83000] SalStrRightX and negative lengths - SalStrRightX_bug.zip

Post by Dave Rabelink » 02 Apr 2005, 00:51

You do not have the required permissions to view the files attached to this post.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3390
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: [D#83000] SalStrRightX and negative lengths - SalStrRightX_bug.zip

Post by Dave Rabelink » 20 Apr 2005, 21:23

Log-A-Bug has reviewed the issue listed below and determined that this
is a defect. The defect number is 83000. This behavior is fixed in
Team Developer 2005.

For further information watch for the fix in the Fixes.Wri file in
future PTF’s or Releases.

SalStrRightX and SalStrRight return incorrect results when passing a
negative parameter.

Thank you,

Log-A-Bug

Return to “gupta.bugreport”

Who is online

Users browsing this forum: [Ccbot] and 0 guests