Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Memory/heap corruption during string manipulation
#2
Okay, having said all that I think I might be able to show something weird happening with that capitalisation line of code in a simpler program.

This code repeatedly sets a string to 'test' and then tries to capitalise the first letter to give 'Test':

Code:
#include <alloc.bas>
dim st$ as string

start()

sub printmem()
    dim f, m as uinteger
    f = memavail
    m = maxavail
    print at 22,0; ink 6; paper 2; flash 1;str$(f);" ";at 22,15;str$(m);" "
    do while inkey$<>""
    loop
    do while inkey$=""
    loop
end sub

sub capstring()
    cls
    print at 0,0;st$
    printmem()
    IF  CODE (st$(1))>96 THEN LET st$(1)=CHR$ ( CODE (st$(1))-32): END IF
    print at 1,0;st$
    printmem()
end sub

sub start()
    
    do
        st$="test"
        capstring()
    loop
    
end sub

The weird thing here is the longer you run the routine, the higher the value of memavail - it just gets bigger and bigger. Would I be correct in assuming it's not supposed to behave like that?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)