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
How C++ class multiple in...
by
Thaddy
[
Today
at 05:20:12 pm]
Converting a Project from...
by
1HuntnMan
[
Today
at 05:09:28 pm]
Round invalid FLT/ invali...
by
PascalDragon
[
Today
at 05:06:01 pm]
crash db navigator with L...
by
jamie
[
Today
at 04:30:49 pm]
TStringGrid draw lines in...
by
Jonny
[
Today
at 04:30:24 pm]
DockedFormEditor trouble
by
majolika
[
Today
at 04:25:26 pm]
How to maximize window us...
by
TBMan
[
Today
at 04:13:21 pm]
[SOLVED] Operators overri...
by
PascalDragon
[
Today
at 04:03:30 pm]
Return nil/null of data t...
by
PascalDragon
[
Today
at 04:00:22 pm]
Copying records with dyna...
by
McDoob
[
Today
at 03:58:38 pm]
Result not being set in c...
by
PascalDragon
[
Today
at 03:56:46 pm]
[SOLVED] Defining custom ...
by
jamie
[
Today
at 03:46:55 pm]
C-library problem with in...
by
PascalDragon
[
Today
at 03:27:53 pm]
Guide Lines Behavior
by
PascalDragon
[
Today
at 03:11:51 pm]
Source Editor - Open Sour...
by
Martin_fr
[
Today
at 03:02:50 pm]
Understanding Constraints
by
majolika
[
Today
at 02:55:05 pm]
كيفية التحكم في مكون main...
by
Gebo
[
Today
at 02:12:27 pm]
مشكلة في استعلام sql
by
Gebo
[
Today
at 02:10:26 pm]
UK's Online Safety Act
by
MarkMLl
[
Today
at 01:49:13 pm]
Lazarus versions...
by
440bx
[
Today
at 11:35:00 am]
Virtual monitor on linux ...
by
MarkMLl
[
Today
at 11:24:29 am]
Lazarus Release Candidate...
by
n7800
[
Today
at 11:11:15 am]
align a panel alClient in...
by
Hansvb
[
Today
at 10:52:23 am]
Using Tesseract without i...
by
backprop
[
Today
at 10:35:44 am]
FPHTTPClient and SSL not ...
by
Thaddy
[
Today
at 10:01:43 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Application crash after Line: 32 (Read 881 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: 6643
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: 6798
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: 2362
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