Skip to content

Loss of data conversion in Flex scanner. #73

Description

@papaathome

In a test project I get the following warning: Details will follow below.

warning C4244: 'return': conversion from 'std::streamsize' to 'int', possible loss of data

Related code:
// YY_INTERACTIVE is not defined, refactored (by removing preprocessor directives) to make it shorter.
int yyFlexLexer::LexerInput( char* buf, int max_size )
{
if ( yyin.eof() || yyin.fail() ) return 0;
(void) yyin.read( buf, max_size );
if ( yyin.bad() ) return -1;
else return yyin.gcount(); // <-- This line is causing the warning
}

I am using Visual Studio 2017 with the latest version of win_bison_flex (win_flex_bison3-latest.zip)
As test project I use the source from Flex Bison C++ Example
There were a few minor things I had to fix but the code compiles and runs without apparent problems.

The scanner code generated by Flex is causing this warning.
I do not see a way to redefine or otherwise fix the definition of int yyFlexLexer::LexerInput(...).
I would like to change it to long long yyFlexLexer::LexerInput(...)

Does anybody have an advise on how to handle this problem?
When parsing large files this can become an issue and I don't like compiler warnings anyway.

Kind regards.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FlexIssues related to Flexdoneupstreamthings that apply/should be done upstream

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions