1. A not-really-important-but-still-a BUG in Eup2

Watch this:

-- Euphoria code from machine.e allocate_string ()
atom mem

    mem = allocate (length(string))        -- Or something like that
    poke (mem, s & 0)

    return mem
end function

-- You better redo this routine

You don't want to be 'out of memory' and using allocate_string...

Ralf
nieuwen at xs4all.nl
ICQ: 9389920
(I've finally got myself ICQ again, this time on my new PII-MMX with Ati 3D
Rage Pro & 32 MB sdRAM 8-)
(I know, I know, I'm being stupid, just had to tell ya all, maybe my age or
something)

new topic     » topic index » view message » categorize

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

>Watch this:
>
>-- Euphoria code from machine.e allocate_string ()
>atom mem
>
>    mem = allocate (length(string))        -- Or something like that
>    poke (mem, s & 0)
>
>    return mem
>end function
>
>-- You better redo this routine
>
>You don't want to be 'out of memory' and using allocate_string...


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.

Oops! I just read the intro line of the code... Rob, that's a programmers
error...

Eagle eye Ralf!

Regards,
    Daniel Berstein.

new topic     » goto parent     » topic index » view message » categorize

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

This is pasted directly from the Euphoria 2.0 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

No bug...

--
                   _____         _____        _____
    ________      /\    \       /\    \      /\    \
   /   \    \    /  \____\     /  \____\    /  \____\
  /  _  \____\  /   / ___/_   /   /____/   /   / ___/_
 /  / \  |____|/   / /\____\ /    \    \  /   / /\____\
 \  \_/ /    / \   \/ / ___/_\     \    \ \   \/ / ___/_
  \    /____/   \    / /\    \\/\   \    \ \    / /\    \
   \   \    \    \   \/  \____\  \   \    \ \   \/  \____\
    \   \    \    \      /    /   \   \____\ \      /    /
     \   \____\    \    /    /     \  /    /  \    /    /
      \  /    /     \  /    /       \/____/    \  /    /
       \/____/       \/____/xseal at harborside.com\/____/

new topic     » goto parent     » topic index » view message » categorize

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

-----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 message » categorize

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

Oops again!

Sorry RDS for my miscomprehension of Ralf's declared pseudo-bug. Anyway,
Ralf's original code did present the problem I issued, and the quote I post
was relevant to the point.

Maybe my participation on this thread wasn't over the actual point Ralf
wanted to present, but it may help beginners to be aware of the problems
"uncontrolled" memory pointers can cause.

Regards,
    Daniel Berstein.

new topic     » goto parent     » topic index » view message » categorize

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

re: allocate_string()

Thanks Ralf and others for bringing this to my attention.
The modification suggested by Greg Harris looks like
a good idea.

Regards,
     Rob Craig
     Rapid Deployment Software

new topic     » goto parent     » topic index » view message » categorize

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

>ICQ: 9389920
>(I've finally got myself ICQ again, this time on my new PII-MMX with Ati 3D
>Rage Pro & 32 MB sdRAM 8-)
>(I know, I know, I'm being stupid, just had to tell ya all, maybe my age or
>something)

Where do you get all this money?

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu