|
From: <tw...@us...> - 2026-03-07 18:25:40
|
Revision: 867
http://sourceforge.net/p/tdbf/code/867
Author: twm
Date: 2026-03-07 18:25:39 +0000 (Sat, 07 Mar 2026)
Log Message:
-----------
Fix FuncLeftString crash on negative count argument
Clamp count to [0, srcLen] to match dBASE semantics. A negative count
was passed unchecked to Append/Move, causing undefined behavior.
Also removed the redundant always-zero index variable.
Modified Paths:
--------------
trunk/src/dbf_prscore.pas
Modified: trunk/src/dbf_prscore.pas
===================================================================
--- trunk/src/dbf_prscore.pas 2026-03-07 18:17:23 UTC (rev 866)
+++ trunk/src/dbf_prscore.pas 2026-03-07 18:25:39 UTC (rev 867)
@@ -1666,14 +1666,15 @@
procedure FuncLeftString(Param: PExpressionRec);
var
- srcLen, index, count: Integer;
+ srcLen, count: Integer;
begin
srcLen := dbfStrLen(Param^.Args[0]);
- index := 0;
count := PInteger(Param^.Args[1])^;
- if index + count > srcLen then
- count := srcLen - index;
- Param^.Res.Append(Param^.Args[0]+index, count)
+ if count < 0 then
+ count := 0;
+ if count > srcLen then
+ count := srcLen;
+ Param^.Res.Append(Param^.Args[0], count)
end;
procedure FuncUppercase(Param: PExpressionRec);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|