> > Probably I am the only one who thinks that the code below is > ridiculous... > > > > procedure TExternalAssemblerOutputFile.AsmWriteFiltered(p: > pchar; > > len: longint); > > var > > s: ansistring; > > begin > > MaybeAddLinePrefix; > > s:=''; // <<< ???? > > setlength(s,len); > > move(p^,s[1],len); > > AsmWriteAnsiStringUnfiltered(decorator.LineFilter(s)); > > end; > > > > --- > > > > I have split feelings: I really like to get the warning/hint at > places > > where it makes sense so I don't want to disable it globally. But > the > > amount of false positives increased significantly :/ > > The compiler is ~400k lines and I had to fix maybe 40 locations, so I > wouldn't call this significantly and there are situations where it > matters, see the result case.
To get a well defined string of a specific length in a single statement: s := StringOfChar(#0, len); I'm not sure if SetLength is a special case in the compiler (like it is in Delphi) or just a plain function call that's normally resolved, but if it is a special case: To get rid of unnecessary warnings for SetLength(x, 0) maybe the compiler could rewrite that into x := nil early on? That should also improve performance. In fact, instead of generating the warning the compiler may even be able to just rewrite non-zero length calls into that StringOfChar statement. _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel