[Lazarus] DateTimeToStr gives an invalid format string error when closing an rdp session

Luca Olivetti luca at wetron.es
Wed Jan 25 09:06:49 CET 2017


El 24/01/17 a les 22:34, Mattias Gaertner via Lazarus ha escrit:
> On Tue, 24 Jan 2017 19:24:35 +0100
> Luca Olivetti via Lazarus <lazarus at lists.lazarus-ide.org> wrote:
>
>> [...]
>> #0 fpc_raiseexception at :0
>> #1
>> SYSUTILS_DATETIMETOSTRING$crc782201FE_STOREFORMAT$ANSISTRING$LONGINT$BOOLEAN
>> at :0
>> #2
>> SYSUTILS_DATETIMETOSTRING$crc782201FE_STOREFORMAT$ANSISTRING$LONGINT$BOOLEAN
>> at :0
>> #3
>> SYSUTILS_DATETIMETOSTRING$ANSISTRING$ANSISTRING$TDATETIME$TFORMATSETTINGS
>> at :0
>> #4 SYSUTILS_DATETIMETOSTRING$ANSISTRING$ANSISTRING$TDATETIME at :0
>> #5 SYSUTILS_DATETIMETOSTR$TDATETIME$$ANSISTRING at :0
>> #6 TLOGGER__INTERNALLOG(0x1eab2390 '127.0.0.1:57233 Nueva
>> conexi'#195#179'n desde 127.0.0.1:57233', <error reading variable>) at
>> D:\boda_t10_l1_pc\comun\utils.pas:149
>> #7 TLOGGER__LOG(0x1eab2390 '127.0.0.1:57233 Nueva conexi'#195#179'n
>> desde 127.0.0.1:57233', <error reading variable>) at
>> D:\boda_t10_l1_pc\comun\utils.pas:190
>
> Start searching for the bug in TLOGGER.LOG.

Armed with a debug version of the rtl I get a different error (sigsev) 
and a different stack trace:

#0 ResumeThread at :0
#1 WideCharToMultiByte at :0
#2 WIN32UNICODE2ANSIMOVE(0x1a5f794 'ene', 0xfe97bd8 'ene', 65001) at 
D:\fpc-2.6.4\rtl\win\syswin.inc:547
#3 GETLOCALESTR(3082, 68, 0x1f69e0 'ene', 0xfe97bd8 'ene') at 
winlazutf8.inc:361
#4 GETLOCALEFORMATSETTINGSUTF8(3082, {CURRENCYFORMAT = 3, NEGCURRFORMAT 
= 8, THOUSANDSEPARATOR = 46 '.', DECIMALSEPARATOR = 44 ',', 
CURRENCYDECIMALS = 2, DATESEPARATOR = 47 '/', TIMESEPARATOR = 58 ':', 
LISTSEPARATOR = 59 ';', CURRENCYSTRING = 0x1f6b10 #128, SHORTDATEFORMAT 
= 0x1feca8 'dd/MM/yyyy', LONGDATEFORMAT = 0x1eea18 'dddd, dd'' de 
''MMMM'' de ''yyyy', TIMEAMSTRING = 0x0, TIMEPMSTRING = 0x0, 
SHORTTIMEFORMAT = 0x1fecc8 'h:nn', LONGTIMEFORMAT = 0x1fece8 'h:nn:ss', 
SHORTMONTHNAMES = {0x1f69e0 'ene', 0x1f69f0 'feb', 0x1f6a00 'mar', 
0x1f6a10 'abr', 0x1f6a20 'may', 0x1f6a30 'jun', 0x1f6a40 'jul', 0x1f6a50 
'ago', 0x1f6a60 'sep', 0x1f6a70 'oct', 0x1f6a80 'nov', 0x1f6a90 'dic'}, 
LONGMONTHNAMES = {0x1fea48 'enero', 0x1fea68 'febrero', 0x1fea88 
'marzo', 0x1feaa8 'abril', 0x1feac8 'mayo', 0x1feae8 'junio', 0x1feb08 
'julio', 0x1feb28 'agosto', 0x1feb48 'septiembre', 0x1feb68 'octubre', 
0x1feb88 'noviembre', 0x1feba8 'diciembre'}, SHORTDAYNAMES = {0x1f6aa0 
'dom', 0x1f6ab0 'lun', 0x1f6ac0 'mar', 0x1f6ad0 'mi'#233, 0x1f6ae0 
'jue', 0x1f6af0 'vie', 0x1f6b00 's'#225'b'}, LONGDAYNAMES = {0x1febc8 
'domingo', 0x1febe8 'lunes', 0x1fec08 'martes', 0x1fec28 
'mi'#233'rcoles', 0x1fec48 'jueves', 0x1fec68 'viernes', 0x1fec88 
's'#225'bado'}, TWODIGITYEARCENTURYWINDOW = 50}) at winlazutf8.inc:436
#5 GETFORMATSETTINGSUTF8 at winlazutf8.inc:474
#6 TAPPLICATION__INTFSETTINGSCHANGE(<error reading variable>) at 
.\include\application.inc:1997
#7 TWINDOWPROCHELPER__DOWINDOWPROC(<error reading variable>) at 
.\win32\win32callback.inc:2307
#8 WINDOWPROC(155124590, 26, 24, 27655548) at .\win32\win32callback.inc:2601
#9 CUSTOMFORMWNDPROC(155124590, 26, 24, 27655548) at 
.\win32\win32wsforms.pp:382
#10 USER32!IsWindowVisible at :0
#11 ?? at :0
#12 ?? at :0
#13 ?? at :0
#14 ?? at :0
#15 USER32!SetThreadDesktop at :0
#16 USER32!GetSystemMenu at :0
#17 ?? at :0


Now, #3 is this function in winlazutf8.inc

function GetLocaleStr(aLocaleID, aLCType: Longint; const Def: string): 
String;
var
   L: Integer;
   Buf: array[0..255] of WideChar;
begin
   L := GetLocaleInfoW(aLocaleID, aLCType, Buf, SizeOf(Buf));
   if L > 0 then
   begin
     Result:='';
     {$IF FPC_FULLVERSION >= 30000}
 
widestringmanager.Wide2AnsiMoveProc(PWideChar(@Buf[0]),Result,CP_UTF8,L-1);
     {$ELSE}
     widestringmanager.Wide2AnsiMoveProc(PWideChar(@Buf[0]),Result,CP_UTF8);
     {$ENDIF}
   end
   else
     Result := Def;
end;

and since this is fpc2.6.4 the call is the second one:

widestringmanager.Wide2AnsiMoveProc(PWideChar(@Buf[0]),Result,CP_UTF8);


which jumps at #2 to

procedure Win32Unicode2AnsiMove(source:punicodechar;var 
dest:ansistring;len:SizeInt);

Uh? The third parameter is supposed to be the length, not the codepage.

If I change that to

widestringmanager.Wide2AnsiMoveProc(PWideChar(@Buf[0]),Result,L-1)

the error disappears.
Reported as http://bugs.freepascal.org/view.php?id=31272


Now, back to my original problem....(TPageControl components randomly 
disappearing)


Bye
-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007


More information about the Lazarus mailing list