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
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Little bit...
by
mas steindorff
[
Today
at 02:03:39 am]
Can /my/ AI help me with ...
by
schuler
[
Today
at 01:48:50 am]
Translate .lfm file in a ...
by
wp
[
Today
at 01:40:24 am]
DataPort or Synpase stat...
by
mas steindorff
[
Today
at 01:39:31 am]
Untitled raycaster game (...
by
hukka
[
Today
at 12:12:06 am]
TChart how setup nicestep...
by
wp
[
Today
at 12:02:04 am]
Renamed a TSQLQuery compo...
by
CraigC
[April 18, 2026, 11:14:18 pm]
FPC 3.2.4-rc1 available
by
marcov
[April 18, 2026, 08:08:03 pm]
Error: Compilation raised...
by
cdbc
[April 18, 2026, 07:02:50 pm]
IDE Coolbar
by
staratel20
[April 18, 2026, 07:02:23 pm]
Building units fails afte...
by
NormanDunbar
[April 18, 2026, 06:39:32 pm]
I hope FreePascal can sup...
by
marcov
[April 18, 2026, 06:03:54 pm]
FPC Unleashed (inline var...
by
ccrause
[April 18, 2026, 04:10:31 pm]
Elite Arcade
by
Guva
[April 18, 2026, 03:41:28 pm]
[SOLVED] Cannot build Uni...
by
Thausand
[April 18, 2026, 02:18:34 pm]
default pin settings, atm...
by
ccrause
[April 18, 2026, 11:45:37 am]
AI assisted translation o...
by
schuler
[April 18, 2026, 03:07:59 am]
Can I get the position an...
by
wp
[April 18, 2026, 12:23:04 am]
Playing video without to ...
by
n7800
[April 17, 2026, 11:51:39 pm]
Delimited text - how find...
by
n7800
[April 17, 2026, 11:28:25 pm]
overloading issues fpc3.2...
by
Martin_fr
[April 17, 2026, 10:21:07 pm]
Ann: Deinline: a de-inlin...
by
LeP
[April 17, 2026, 09:58:08 pm]
Seeking advice on setting...
by
schuler
[April 17, 2026, 03:36:28 pm]
Ann: DeCoperators
by
DomingoGP
[April 17, 2026, 03:23:39 pm]
TLazSerial : serial port ...
by
CM630
[April 17, 2026, 09:50:34 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Application crash after Line: 32 (Read 1157 times)
paule32
Hero Member
Posts: 645
One in all. But, not all in one.
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
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.
rvk
Hero Member
Posts: 6989
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
Hero Member
Posts: 645
One in all. But, not all in one.
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
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.
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: 7663
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: 2482
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