View Issue Details

IDProjectCategoryView StatusLast Update
0038092FPCCompilerpublic2020-11-17 11:47
ReporterSam Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformWin32OSWin10 
Product Version3.2.0 
Summary0038092: Bad ansistring const value when empty
DescriptionSince B = '', the code below should write
start<ins:testcom><ins:testa>A</ins:testa></ins:testcom>end
but write
start<ins:testcom><ins:testa>A</ins:testa></ins:testcom><ins:testcom><ins:testa>A</ins:testa></ins:testcom>end
Steps To ReproduceJust run the code below:

function WS_XML(const cle, valeur: string): string;
begin
  if valeur <> '' then
    result := '<' + cle + '>' + valeur + '</' + cle + '>';
end;

function Req(const A, B: string): string;
begin
  result := 'start' +
           WS_XML('ins:testcom', WS_XML('ins:testa', A)) +
          WS_XML('ins:testcom', WS_XML('ins:testb', B)) +
          'end';
end;

begin
  writeln(Req('A', ''));
end.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Michael Van Canneyt

2020-11-17 11:47

administrator   ~0126996

Your code is wrong, it is not setting result when valuer=''. Change to

function WS_XML(const cle, valeur: string): string;
begin
  if valeur <> '' then
    result := '<' + cle + '>' + valeur + '</' + cle + '>';
  else
   Result:='';
end;

Result is not initialized and not guaranteed to be empty.

This is explicitly documented in:
https://www.freepascal.org/docs-html/current/ref/refse93.html
https://www.freepascal.org/docs-html/current/ref/refse93.html#x176-19800014.3

Issue History

Date Modified Username Field Change
2020-11-17 11:39 Sam New Issue
2020-11-17 11:47 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-11-17 11:47 Michael Van Canneyt Status new => resolved
2020-11-17 11:47 Michael Van Canneyt Resolution open => no change required
2020-11-17 11:47 Michael Van Canneyt FPCTarget => -
2020-11-17 11:47 Michael Van Canneyt Note Added: 0126996