Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
Application crash after Line: 32
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Type Library Viewer, Impo...
by
UamhForever
[
Today
at 03:12:22 am]
Developing a Kernel Modul...
by
Joanna from IRC
[
Today
at 03:06:52 am]
Use tts0, This example is...
by
Jurassic Pork
[
Today
at 02:18:37 am]
Python4Lazarus Undefined ...
by
Jurassic Pork
[
Today
at 02:07:28 am]
Show Form at Top
by
TRon
[
Today
at 12:48:24 am]
Problem with Hints
by
simsee
[
Today
at 12:08:54 am]
ZDataset.Locate + loParti...
by
Sieben
[December 03, 2024, 11:30:03 pm]
Zaos Transliteration on l...
by
hamacker
[December 03, 2024, 11:12:53 pm]
Breakpoint dosn't work
by
Joanna from IRC
[December 03, 2024, 11:04:55 pm]
[SOLVED] Howto use a DEFI...
by
PascalDragon
[December 03, 2024, 09:42:38 pm]
Random SnowFlakes:
by
Boleeman
[December 03, 2024, 09:07:14 pm]
AVRPascal – free code edi...
by
ackarwow
[December 03, 2024, 09:04:00 pm]
Secondary Installation fo...
by
TRon
[December 03, 2024, 08:21:03 pm]
Error when attempting to ...
by
dsiders
[December 03, 2024, 08:01:39 pm]
The Form cannot be resize...
by
daxnet
[December 03, 2024, 02:51:42 pm]
Api/component pack for Ra...
by
MarkMLl
[December 03, 2024, 02:15:57 pm]
kernel 6.8 and checking s...
by
MarkMLl
[December 03, 2024, 02:13:41 pm]
storing string
by
Thaddy
[December 03, 2024, 09:38:41 am]
OverLapping Snowflake Fra...
by
Boleeman
[December 03, 2024, 09:04:01 am]
[SOLVED] StringGrid color...
by
Vodnik
[December 03, 2024, 08:26:44 am]
YM Player
by
TRon
[December 03, 2024, 02:32:16 am]
How single procedure ends...
by
Marion
[December 03, 2024, 01:57:43 am]
ct2laz - convertor betwee...
by
Sharfik
[December 03, 2024, 01:26:03 am]
Amigo programming languag...
by
maurog
[December 02, 2024, 11:19:44 pm]
[SOLVED] How to document ...
by
korba812
[December 02, 2024, 10:49:39 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Application crash after Line: 32 (Read 833 times)
paule32
Sr. Member
Posts: 280
Application crash after Line: 32
«
on:
February 29, 2024, 11:17:26 pm »
Hello,
the Code above produce me an Application Crash after Line: 32.
How can I fix this ?
The Code, I use it under Windows 10 64-Bit.
Code: Pascal
[Select]
[+]
[-]
procedure
fpc_ansistr_assign
(
var
DestS
:
Pointer
;
S2
:
Pointer
)
;
[
public
,
alias
:
'FPC_ANSISTR_ASSIGN'
]
;
compilerproc
;
begin
MessageBox
(
0
,
LPCSTR
(
S2
)
,
'0 0 0 0 0'
,
0
)
;
DestS
:
=
malloc
(
200
)
;
{$ASMMODE INTEL}
asm
mov rsi
,
S2
// src string
mov rdi
,
DestS
// dst string
xor
rax
,
rax
// counter for string length
@
findLength
:
cmp
byte
ptr
[
rsi
+
rax
]
,
0
je
@
copyInit
// null terminator
inc rax
jmp
@
findLength
@
copyInit
:
mov rcx
,
rax
// rcx now holds the length of the string
@
copyLoop
:
test rcx
,
rcx
// check if RCX is empty
jz
@
endCopy
// when yes => done.
dec rcx
mov al
,
[
rsi
+
rcx
]
// load byte from src in AL
mov
[
rdi
+
rcx
]
,
al
// store byte into dst
jmp
@
copyLoop
// to next charcter
@
endCopy
:
mov
byte
ptr
[
rdi
+
rax
]
,
0
// null-terminated dst string
end
;
MessageBox
(
0
,
LPCSTR
(
S2
)
,
'1 1 0 1 0'
,
0
)
;
MessageBox
(
0
,
LPCSTR
(
DestS
)
,
'0 0 0 0 0'
,
0
)
;
end
;
Logged
rvk
Hero Member
Posts: 6572
Re: Application crash after Line: 32
«
Reply #1 on:
February 29, 2024, 11:30:28 pm »
fpc_ansistr_assign is normally an essential part of the RTL.
In that procedure you can messagebox multiple times.
Are you absolutely sure those functions don't call fpc_ansistr_assign themselves because then you get an infinite loop.
Remove the messageboxes.
Does it still crash?
If so... On what line?
Logged
paule32
Sr. Member
Posts: 280
Re: Application crash after Line: 32
«
Reply #2 on:
February 29, 2024, 11:34:13 pm »
the Function will not call it'self.
The first, and second MessageBox will be pop out on screen.
So, there is no Loop.
But the DestS seems be not valide
Logged
KodeZwerg
Hero Member
Posts: 2269
Fifty shades of code.
Re: Application crash after Line: 32
«
Reply #3 on:
February 29, 2024, 11:45:50 pm »
I just transaled your asm back to pascal to find out things, here it works okay.
Code: Pascal
[Select]
[+]
[-]
procedure
FPC_ANSISTR_ASSIGN
(
var
DestS
:
PChar
;
S2
:
PChar
)
;
var
Len
:
Integer
;
begin
MessageBox
(
0
,
S2
,
'0 0 0 0 0'
,
0
)
;
GetMem
(
DestS
,
200
)
;
try
Len
:
=
0
;
while
S2
[
Len
]
<>
#0
do
Inc
(
Len
)
;
Move
(
S2
^
,
DestS
^
,
Len
)
;
DestS
[
Len
]
:
=
#0
;
finally
// FreeMem(DestS); // must be done outside else the pointer is garbage after method runs out of scope
end
;
MessageBox
(
0
,
S2
,
'1 1 0 1 0'
,
0
)
;
MessageBox
(
0
,
DestS
,
'0 0 0 0 0'
,
0
)
;
end
;
Logged
«
Last Edit:
Tomorrow
at 31:76:97 xm by
KodeZwerg
»
jamie
Hero Member
Posts: 6734
Re: Application crash after Line: 32
«
Reply #4 on:
March 01, 2024, 01:05:59 am »
Lots of holes on that ASM code.... it's like the slit experiment!
Logged
The only true wisdom is knowing you know nothing
ASerge
Hero Member
Posts: 2336
Re: Application crash after Line: 32
«
Reply #5 on:
March 01, 2024, 01:57:37 am »
Quote from: jamie on March 01, 2024, 01:05:59 am
Lots of holes on that ASM code.... it's like the slit experiment!
I agree. Better FPC code:
Code: Pascal
[Select]
[+]
[-]
procedure
FPC_ANSISTR_ASSIGN
(
out DestS
:
PAnsiChar
;
S2
:
PAnsiChar
)
;
var
Len
:
SizeInt
;
begin
DestS
:
=
nil
;
if
S2
=
nil
then
Exit
;
Len
:
=
IndexByte
(
S2
^
,
-
1
,
0
)
;
if
Len >
0
then
// the only #0 is ignored
begin
Inc
(
Len
)
;
// + #0
GetMem
(
DestS
,
Len
)
;
Move
(
S2
^
,
DestS
^
,
Len
)
;
end
;
end
;
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
Application crash after Line: 32
TinyPortal
© 2005-2018