Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with UDTs and Strings / PSA
#1
I've run across a bug(s) with variable length strings nested within a UDT.

It manifested itself when I had some variables that originate from a UDT that should have been initialized to zero, but were instead a random value.

This is a stripped down example of the issue(s).

Its seems that if you nest a variable length string in a UDT It can causes crashes.

Variable length strings in this case is convenient for me because the LEN function reports the actual length of string, not the allocated block of memory. This makes the string parsing and manipulation easier.

The workaround would to use fixed length strings and roll my own LEN function.

I'm using Linux and QB v3.13.0

Code: (Select All)
'Nested String UDT Issues

TYPE tUDT_NEST_DEEPER
'If I comment out the 'a' element, and the element 's' is not
' a fixed length, the elements do not initialize to zero properly.
a AS LONG
's AS STRING * 10 ' Works with no issue
s AS STRING ' broken
b AS LONG
END TYPE

TYPE tUDTNEST
s AS STRING
n AS LONG
u AS tUDT_NEST_DEEPER
END TYPE

TYPE tUDT
a AS LONG
b AS tUDTNEST
c AS LONG
END TYPE

DIM test AS tUDT

'The following should initialize to 0 or blank
PRINT " These should all be zero or blank."
PRINT "test.a = "; test.a
PRINT "test.b.s = "; test.b.s
PRINT "test.b.n = "; test.b.n
PRINT "test.c = "; test.c

'Uncomment for crash, if you are using variable length strings
'PRINT "test.b.u.s = "; test.b.u.s
'PRINT "test.b.u.b = "; test.b.u.b
Reply


Messages In This Thread
Issue with UDTs and Strings / PSA - by justsomeguy - 07-27-2024, 07:15 AM
RE: Issue with UDTs and Strings / PSA - by luke - 07-27-2024, 11:01 AM
RE: Issue with UDTs and Strings / PSA - by bplus - 07-27-2024, 02:57 PM
RE: Issue with UDTs and Strings / PSA - by luke - 08-09-2024, 01:03 PM
RE: Issue with UDTs and Strings / PSA - by Pete - 08-09-2024, 02:46 PM



Users browsing this thread: 1 Guest(s)