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
Custom self drawn compone...
by
Artur W.
[
Today
at 04:33:41 pm]
visasession
by
Laksen
[
Today
at 04:21:54 pm]
Length of String is not f...
by
BrunoK
[
Today
at 04:03:35 pm]
Treeview: full-width back...
by
wp
[
Today
at 04:00:16 pm]
TBGRASpeedButton not show...
by
Mastropiero
[
Today
at 03:43:01 pm]
Hi there
by
LV
[
Today
at 03:26:06 pm]
Feature request - new "fi...
by
cdbc
[
Today
at 03:11:43 pm]
Using Heaptrace with Linu...
by
cdbc
[
Today
at 03:10:14 pm]
using RunCommand to wrap ...
by
MarkMLl
[
Today
at 03:06:16 pm]
Accessing parent form fro...
by
nikel
[
Today
at 01:25:37 pm]
Random Carpet Designs: La...
by
majolika
[
Today
at 01:18:49 pm]
changing the position of ...
by
paweld
[
Today
at 11:37:07 am]
MyLangEdit 2.0 for editin...
by
marcov
[
Today
at 11:24:44 am]
Scrollbox, scrollbar Back...
by
bbrx
[
Today
at 10:33:39 am]
Why free pascal suppress ...
by
tetrastes
[
Today
at 10:20:33 am]
Bug and crash. I think th...
by
veb86
[
Today
at 09:12:17 am]
dbgrid picklist detect wh...
by
cdbc
[
Today
at 08:43:31 am]
how i can use ODBC SQL Q...
by
Zvoni
[
Today
at 08:42:04 am]
IBSQL - CheckClosed
by
sydenis
[
Today
at 08:40:40 am]
[Solved] GetCurrentDir is...
by
Zvoni
[
Today
at 08:35:52 am]
Random Carpet Designs:Rep...
by
Boleeman
[
Today
at 05:07:14 am]
Failed to connect to a si...
by
MarkMLl
[February 09, 2025, 10:16:12 pm]
What's up with PtcCrt's d...
by
TBMan
[February 09, 2025, 10:07:17 pm]
FPC can't link screen_dem...
by
marcov
[February 09, 2025, 09:22:40 pm]
Transparent animation
by
majolika
[February 09, 2025, 08:22:22 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Application crash after Line: 32 (Read 887 times)
paule32
Sr. Member
Posts: 286
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: 6658
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: 286
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: 6801
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: 2376
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