Re: A not-really-important-but-still-a BUG in Eup2

new topic     » goto parent     » topic index » view thread      » older message » newer message

-----Original Message-----
From: Daniel Berstein <danielberstein at USA.NET>
To: Multiple recipients of list EUPHORIA <EUPHORIA at MIAMIU.ACS.MUOHIO.EDU>
Date: Monday, April 06, 1998 8:02 PM
Subject: Re: A not-really-important-but-still-a BUG in Eup2


>>Watch this:
--snip--


>I don't understand the bug. From your example I see you poked
>length(string)+1 bytes on a length(string) buffer. That's a programmers
>error, not an Euphoria bug.


Here is the code from machine.e:

global function allocate_string(sequence s)
-- create a C-style null-terminated string in memory
    atom mem

    mem = allocate(length(s) + 1)
    poke(mem, s & 0)
    return mem
end function

The "bug" lies in the fact that the variable mem is not checked to see if it
was able to be allocated (mem != 0)before sequence s is poked into memory.
The code should have been written like this (for example):

global function allocate_string(sequence s)
-- create a C-style null-terminated string in memory
    atom mem

    mem = allocate(length(s) + 1)
    if mem != 0  then
           poke(mem, s & 0)
    end if
    return mem
end function

It now checks to see if the string can be allocated. If it can, it pokes
then sequence into memory and returns the address. If it cannot allocate the
string, function returns 0.

I think that was the bug Ralf was taking about.?.

Regards,

Greg Harris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu