[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Structures with byte arrays using fromstring cause segfault


When Working with structures with byte arrays, the copy of a string to the byte array
using fromstring() appears to corrupt memory

But using the tostring() seems to work correctly.

I have included  a simple script to demonstrate the issue.
The first line does a fromstring() and initially appears to do nothing.

But the last line that frees the allocated memory causes a segfault sometimes.

Removing the line doing the fromstring() makes everything ok on the free.

Maybe I am using this in an incorrect way?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#!/usr/bin/env gbs3

public struct demo
    tag[100] as byte
end struct

public dtag as demo = alloc(400)
public theString as string = "This is a test string tag"

public sub main()
    dtag.tag.fromstring(theString)

    print "Tag=";dtag.tag.tostring() ' prints nothing and in fact the content is not changed.

    for i as integer = 0 to theString.len-1
       dtag.tag[i] = asc(theString[i])
    next
    dtag.tag[i+1]=0

    print "Tag=";dtag.tag.tostring()

    free(varptr(dtag))
end

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


--
~~~~ Brian

Attachment: OpenPGP_0x78BFB26402F48419.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


Follow-Ups:
Re: Structures with byte arrays using fromstring cause segfaultJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>