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
TSynEdit XML tag completi...
by
Martin_fr
[
Today
at 09:09:44 pm]
Fpcupdeluxe
by
Fred vS
[
Today
at 08:55:58 pm]
Weird error: component no...
by
heebiejeebies
[
Today
at 08:16:21 pm]
Warning on identifier usa...
by
Martin_fr
[
Today
at 08:11:02 pm]
Planet designer
by
Lulu
[
Today
at 07:40:54 pm]
I'm puzzled and bewildere...
by
cdbc
[
Today
at 07:25:29 pm]
Radio Buttons cause a "ST...
by
cdbc
[
Today
at 07:14:02 pm]
ld: library 'gtk-3' not f...
by
zeljko
[
Today
at 07:10:52 pm]
Option "RemoveExpressionR...
by
Thaddy
[
Today
at 07:03:42 pm]
basic question for good s...
by
Nicole
[
Today
at 06:42:17 pm]
Converting a Project from...
by
1HuntnMan
[
Today
at 05:01:02 pm]
TStringGrid AlternateC...
by
Nicole
[
Today
at 04:46:45 pm]
Lazarus Windows apps in M...
by
Xenno
[
Today
at 04:36:19 pm]
Lazarus Release Candidate...
by
baldzhang
[
Today
at 04:03:08 pm]
Displying tooltips for ea...
by
Zvoni
[
Today
at 03:10:51 pm]
ParambyName - how to stri...
by
Zvoni
[
Today
at 03:04:49 pm]
link error on Ubuntu 22.0...
by
tetrastes
[
Today
at 02:06:17 pm]
/lib/x86_64-linux-gnu/lib...
by
Fred vS
[
Today
at 02:04:28 pm]
A question on Modula2 vs ...
by
Thaddy
[
Today
at 01:22:47 pm]
DateUtils *Span and *Betw...
by
Чебурашка
[
Today
at 12:13:14 pm]
"database not open" - IBX...
by
Nicole
[
Today
at 11:54:25 am]
How to Run Lazarus App wi...
by
incendio
[
Today
at 04:59:33 am]
ADUG Symposium 2025 is on
by
Mathias Burbach
[
Today
at 02:10:05 am]
Rest API chunk file downl...
by
Leledumbo
[
Today
at 01:01:56 am]
CPU-View
by
Martin_fr
[March 25, 2025, 08:49:41 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Application crash after Line: 32 (Read 916 times)
paule32
Sr. Member
Posts: 330
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: 6695
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: 330
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: 6836
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: 2389
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