From: detlef.tietgen on
There is a difference behaviour between VC7 and VC8 (8.0.50727.42).
When I run the following program in VC8 in DEBUG, I get a DEBUG
ASSERTION in 'isatty.c" at line 45:

_VALIDATE_RETURN((fh >= 0 && (unsigned)fh <
(unsigned)_nhandle), EBADF, 0);

In VC7 everything runs fine !!

Here the complete test program:
#include "stdafx.h"
#include "string.h"
#include "io.h"

int _tmain(int argc, _TCHAR* argv[])
{
char txt[128];
FILE *fpFile;

strcpy (txt, "This is a test");
fpFile = (FILE * )txt;
isatty( fileno(fpFile)); <----- DEBUG ASSERTION
return 0;
}

Now my problem is, that this line was generated by FLEX, so I can't
change it. Is there any work around or HotFix or Patch ?

From: Igor Tandetnik on
<detlef.tietgen(a)odt-oce.com> wrote in message
news:1166103977.218712.286670(a)73g2000cwn.googlegroups.com
> There is a difference behaviour between VC7 and VC8 (8.0.50727.42).
> When I run the following program in VC8 in DEBUG, I get a DEBUG
> ASSERTION in 'isatty.c" at line 45:
>
> _VALIDATE_RETURN((fh >= 0 && (unsigned)fh <
> (unsigned)_nhandle), EBADF, 0);
>
> In VC7 everything runs fine !!
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> char txt[128];
> FILE *fpFile;
>
> strcpy (txt, "This is a test");
> fpFile = (FILE * )txt;
> isatty( fileno(fpFile)); <----- DEBUG ASSERTION

Well, you pass garbage to a function - you should be glad it tells you
about this fact, rather than failing silently as it apparently used to
do. What is this code supposed to achieve anyway?

> Now my problem is, that this line was generated by FLEX, so I can't
> change it. Is there any work around or HotFix or Patch ?

Contact the authors of FLEX. If FLEX really generates code that casts a
char* pointer to FILE*, it has a bug.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


From: detlef.tietgen on
Well, you are right.
and
Well, you are not right.

This is only a sample. In the code, is goes through different
interfaces from char* to void * to void * to FILE * and the function
yyparse() detects with this, whether a char * or a FILE * is passed.

What I like to show is the difference in the BEHAVIOUR between debug
VC7 and debug VC8 code.
Greetings
DeT

> Well, you pass garbage to a function - you should be glad it tells you
> about this fact, rather than failing silently as it apparently used to
> do. What is this code supposed to achieve anyway?
>
> > Now my problem is, that this line was generated by FLEX, so I can't
> > change it. Is there any work around or HotFix or Patch ?
>
> Contact the authors of FLEX. If FLEX really generates code that casts a
> char* pointer to FILE*, it has a bug.
> --
> With best wishes,
> Igor Tandetnik

From: Ulrich Eckhardt on
Please don't top post, please don't snip attributions when quoting someone.

detlef.tietgen(a)odt-oce.com wrote:
> This is only a sample. In the code, is goes through different
> interfaces from char* to void * to void * to FILE * and the function
> yyparse() detects with this, whether a char * or a FILE * is passed.

Well, obviously this doesn't work. You can't go and throw a random pointer
at isatty() and expect it to detect if it is a filedescriptor or not.

> What I like to show is the difference in the BEHAVIOUR between debug
> VC7 and debug VC8 code.

Well, one just silently swallows the abuse while the other catches the error
and gives you a message. The FLEX code is broken nonetheless.

Just as an advise for a quick fix: you could use the fact that FILE* are
aligned to a much larger bound than a char pointer has to be. IOW, you
could just use e.g. malloc() to allocate storage for the char* and then
pass the result plus one and detect that the storage is unaligned later.
However, this is still a pretty gross hack and in the long run I'd rather
get FLEX properly fixed.

Uli