Jump to content


Photo
- - - - -

A horrible bug....


77 replies to this topic

#1 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

Posted 16 July 2001 - 12:59 PM

Hi,

Just thought I would let you know....

We found a horrible bug that actually lets you assign another value to a numeric literal.

If call a Global Function and pass a numeric literal to that function and the global function changes that parameter then once back in the calling function that literal remains changed.

For example, if function FUN1 calls Global LS function GFUN1 and passes the literal 1 in a parameter list and the global function GFUN1 modifies that parameter to 6 (Now I know that you should not do this, but due to human error this could occur, and does) then once back into FUN1, if you do a UMSG('Val:' CONV(1),-1) you get 6 output!!!!

This is the second time we have had this, and it has take the programmer quite alot of time to workout what was going on.

On a side note, It was quite useful to have access to the Bootstrap files so that we could write a function to find these 'problem' functions.... Something we may not have the privilege of doing in the future... :)

I would certainly not want to go through our 200 Global Functions manually every few weeks looking for this bug.

Rob D

#2 Ralph Gadsby

Ralph Gadsby

    Expert

  • Members
  • PipPipPipPip
  • 154 posts
  • Gender:Male
  • Location:United Kingdom

Posted 16 July 2001 - 02:00 PM

This is NOT a bug.

Use Developer Studio! This has a warning message in it to warn a programmer that they have made a coding error if they code a literal as a global function parameter that is either type B or O. Developer Studio also issues another warning if you try to gen a function with a literal passed as a parameter.

I'm sure that VIP will also have similar checks.

#3 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

Posted 16 July 2001 - 02:32 PM

Hi,

I'll have to argue about it not being a bug.... You should not be able to change the value of a literal. Period.

When would that be needed???

Sorry, going to DS is not really an option for us.

I really dont think that our customer would like the slow down with development due to the learning curve and the way DS works. They want to see new functionality in their system not a GUI development system. Going to DS has no value to us.

This would cost them alot of money as there are 25 developers in our team, and PRO-AIDE is the quickest development env. there is.

The other point I was trying to make was that there are times that we need to modify/search through the bootstrap files freely.....

Rob D

#4 Dan Shannon

Dan Shannon

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 374 posts
  • Gender:Male
  • Location:Australia

Posted 16 July 2001 - 04:58 PM

I agree - this is a BUG. You can't change the value of NUMBERS! They're NOT variables, so you can't change them. End of argument. Unless you want 1 1=12 to be suddenly correct, which is patently ridiculous...

Dan Shannon

#5 Mike Schoen

Mike Schoen

    Expert

  • Members
  • PipPipPipPip
  • 198 posts
  • Gender:Male
  • Location:Guelph, Canada

Posted 16 July 2001 - 06:11 PM

This handy little 'feature' also works with literals like
'Y' and 'N':

create a global with a 'B' parameter that changes that parameter to 'N'

Call this global and pass it 'y' as a parameter...
for the rest of the calling function's logic,
IF 'Y' = 'N' will now be true...

#6 Ralph Gadsby

Ralph Gadsby

    Expert

  • Members
  • PipPipPipPip
  • 154 posts
  • Gender:Male
  • Location:United Kingdom

Posted 17 July 2001 - 08:22 AM

This is a feature of languages that have call by reference. For example in early versions of Fortran the same problem could be encountered.

#7 Mike Nicholson

Mike Nicholson

    Expert

  • Members
  • PipPipPipPip
  • 196 posts
  • Gender:Male
  • Location:Stockholm, Sweden

Posted 17 July 2001 - 10:10 AM

Then early versions of Fortran had a bug in them - you should never be able to change the value of a literal!! Besides - are you really comparing ProIV to fortran, we've supposedly moved on a bit since then ;-)

Cheers

Mike

#8 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

Posted 17 July 2001 - 10:16 AM

I give up!!!

How is this possible in say 'C'.... ?

If you are comparing PROIV to 'early versions' of Fortran then there is no hope for the future of PROIV.

Rob D

#9 Steve Jenkins

Steve Jenkins

    Advanced

  • Members
  • PipPipPip
  • 58 posts
  • Gender:Male
  • Location:Cardiff, United Kingdom

Posted 17 July 2001 - 11:18 AM

From the National Press...

'Due to a mixup between the numbers 5 and 7 NASA made a huge mistake earlier today. Ensign Gadsby who was chosen to eliminate the mad genious Captain Mellis on the 5th planet from the Sun actually landed on the 7th. NASA only realised the blunder after this transmission was received.

Houston: Gadsby, confirm you current position.
Gadsby : Houston, uhh current position unknown. I think I can see Jupiter out of the port window.
Houston: Ah, standby.
Gadsby : Roger, standby.
Houston: Ah, Gadsby we have your last transmission from Uranus.
Gadsby : Houston, we have a problem.
Houston: Standby....We have spoken to technical and they tell us although you are transmitting from Uranus it's Ok because 7 does in fact equal 5 and therefore Uranus is in fact Jupiter.
Gadsby : Thankyou Houston. It all makes sense now.'

#10 Ralph Gadsby

Ralph Gadsby

    Expert

  • Members
  • PipPipPipPip
  • 154 posts
  • Gender:Male
  • Location:United Kingdom

Posted 17 July 2001 - 11:47 AM

C does not have call by reference.

I was not comparing ProIV to Fortran, merely citing Fortran as one other language that has call by reference.

#11 Guest_Bob_*

Guest_Bob_*
  • Guests

Posted 17 July 2001 - 02:36 PM

Ralph why don't you use you PRO-IV email address !

#12 Richard Bassett

Richard Bassett

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 696 posts
  • Location:Rural France

Posted 17 July 2001 - 03:44 PM

If this is not a 'bug' it is presumably ProIV Behaving As Designed (BAD). As such it is a design error in the language.

I remember noticing this years ago using global logic (before global functions even existed). I expect it's still BAD there too - I wonder if DS spots that?

This is not an inherent 'feature' of languages that have call by reference. Most compilers end up placing constants in a separate memory segment to variables and a runtime error should arise if you try to write to the address of a constant (effectively in read-only memory)

Although C may may not have call-by-reference explicitly, it has for all practical purposes because it has pointers - you can simply pass the pointer as an argument.

One reason C has the const keyword is so issues like this can be made safe and explicit (a reference to a constant is not an lvalue and so on).

I'm with Rob - no self-respecting language should allow you to inadvertently change the value of a literal.
Nothing's as simple as you think

#13 Tim Woodall

Tim Woodall

    Member

  • Members
  • PipPip
  • 20 posts

Posted 17 July 2001 - 04:39 PM

>This is not an inherent 'feature' of languages that have call by reference. Most compilers end up placing constants in a separate memory segment to variables and a runtime error should arise if you try to write to the address of a constant (effectively in read-only memory)

This IS a feature of pass by reference. In all (at least all that I know of) languages that allow literals to be passed by reference a copy of the literal has to be made in order to pass a reference to it.

>Although C may may not have call-by-reference explicitly, it has for all practical purposes because it has pointers - you can simply pass the pointer as an argument.

No. Pass by pointer is pass by value. You are passing the value of the pointer.

>One reason C has the const keyword is so issues like this can be made safe and explicit (a reference to a constant is not an lvalue and so on).

There are no references in C. In C plus plus (anyone know how to get a plus?) yes there are references and you have to have const references in order to pass a literal. This may involve calling of constructors and destructors and other unexpected effects.

However, changing the value of a literal is not even limited to pass by reference. In some versions of C it was possible to change the value of a constant string.

e.g.

'Hello World
'[5]='
';
printf('Hello World
');

Would print
Hello
World

Rather than
Hello World

This is not a bug, and is even 'allowed' by the C standards because you are invoking undefined behaviour.

#14 Ralph Gadsby

Ralph Gadsby

    Expert

  • Members
  • PipPipPipPip
  • 154 posts
  • Gender:Male
  • Location:United Kingdom

Posted 17 July 2001 - 04:41 PM

So Lisp, Perl and COBOL are not self-respecting languages. I believe that all of these languages allow call by reference for literals and will change the literal without warning. OK, the compilers on some, but not all, machines for these languages will produce compile a time error - a message to the effect that you can't change a read only variable.

#15 Tim Woodall

Tim Woodall

    Member

  • Members
  • PipPip
  • 20 posts

Posted 17 July 2001 - 04:46 PM

'Hello World '[5]=' ';

There was a backslash n in those single quotes in preview - honest :-(



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users