PB 6.40 a3 Concat with string pointer

Just starting out? Need help? Post your questions and find answers here.
fryquez
Enthusiast
Enthusiast
Posts: 397
Joined: Mon Dec 21, 2015 8:12 pm

PB 6.40 a3 Concat with string pointer

Post by fryquez »

Code: Select all

buf = AllocateMemory(512)
PokeS(buf, "Hallo")

*s.string = @buf
Debug *s\s + "!"
User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.40 a3 Concat with string pointer

Post by mk-soft »

No bug

The type string has changed. It is no longer a pointer on a string, but the type string is now a structured type with lengths. It must be a valid PB string.
You must take with PeekS on your memory area.

Code: Select all

text.String\s = "Hello"
*s.string = @text
ShowMemoryViewer(@*s\s - SizeOf(Integer), 32)
Debug *s\s + "!"
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
fryquez
Enthusiast
Enthusiast
Posts: 397
Joined: Mon Dec 21, 2015 8:12 pm

Re: PB 6.40 a3 Concat with string pointer

Post by fryquez »

Of course it's a bug. You have the same situation with fixed strings, these also don't have the size prefixed.

For fixed strings PB now makes a temporary copy that than get passed to SYS_ConcatString.
At least the same should be done here.
User avatar
ChrisR
Addict
Addict
Posts: 1586
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB 6.40 a3 Concat with string pointer

Post by ChrisR »

.
Last edited by ChrisR on Wed Feb 04, 2026 2:33 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.40 a3 Concat with string pointer

Post by mk-soft »

@Chris,

You write the length of the string outside the allocated memory.

Corrected ...

Code: Select all

buf = AllocateMemory(512)
Lenght = PokeS(buf+SizeOf(Integer), "Hallo")
ShowMemoryViewer(buf, Lenght + SizeOf(Integer))
PokeI(buf,  Lenght / SizeOf(Character))
ShowMemoryViewer(buf, Lenght + SizeOf(Integer))
*str = buf + SizeOf(Integer)
*s.string = @*str
Debug *s\s + "!"
Not Official. You should not use an intera from Purebasic here, because something can always change here. Better to use PeekS!
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
ChrisR
Addict
Addict
Posts: 1586
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB 6.40 a3 Concat with string pointer

Post by ChrisR »

.
Last edited by ChrisR on Wed Feb 04, 2026 2:33 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.40 a3 Concat with string pointer

Post by mk-soft »

@Chris

You write your string length again before the allocated memory. Your memory starts at "buf" and not 8 bytes before
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
ChrisR
Addict
Addict
Posts: 1586
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB 6.40 a3 Concat with string pointer

Post by ChrisR »

.
Last edited by ChrisR on Wed Feb 04, 2026 2:33 am, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.40 a3 Concat with string pointer

Post by mk-soft »

:?
Turn on the purifier

You set the pointer *p to 8 bytes before allocated memory and then pokes into the memory before allocated buffer.
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
kenmo
Addict
Addict
Posts: 2082
Joined: Tue Dec 23, 2003 3:54 am

Re: PB 6.40 a3 Concat with string pointer

Post by kenmo »

Not a bug... incorrect use of pointer... A string in the new 6.40 system now consists of the character data (with null terminator still), and length info and flag bits...
You can't point a PB 6.40 string pointer directly at the raw character data missing the other info and expect it to work correctly. I think Fred and Freak will confirm this.

EDIT: And ChrisR, you can't allocate a buffer at address (buf) and then write numeric data before (buf) :shock: Crashes and bugs will happen!
User avatar
ChrisR
Addict
Addict
Posts: 1586
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB 6.40 a3 Concat with string pointer

Post by ChrisR »

Sorry, I'm preoccupied with other, more important things right now and I shouldn't have written here in the first place. The best I can do is delete my buggy posts
User avatar
mk-soft
Always Here
Always Here
Posts: 6603
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.40 a3 Concat with string pointer

Post by mk-soft »

Should not delete the bug code. I didn't do it with my bugs and just wrote on how not to do it.
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
Post Reply