Compile warning in baseprovider.cpp

Description

src\tiles\providers\baseprovider.cpp(108): warning C4244: 'initializing': conversion from 'std::streamoff' to 'int', possible loss of data

Activity

Show:
Paul Meems
July 12, 2019, 10:42 AM

Some suggestions:
https://stackoverflow.com/questions/15172315/c-resolving-istreamtellg-warning

I’ve asked the original author of this piece of code too look at it:

Jerry Faust
July 18, 2019, 5:09 PM
Edited

Here's the current code segment:

Looking this over, the fl.tellg() method returns a streamoff, which is actually a long long value. This is why the compiler warns of a possible loss of data. However, a couple lines down, the sz value is used to initialize the size of the vector, which wants a size_t,which is an unsigned int value. So no matter what, we're going to have to deal with the size change.

What I recommend is the following, rather than assigning the streamoff value to an int, assign it into a size_t, and cast the streamoff value to a size_t:

It’s true that we will have a problem if the stream length is ever greater than an unsigned int can hold, but that’s a separate problem, if we’re just addressing the compiler warning.

Paul Meems
August 2, 2019, 8:36 AM

I’ve made the changes as recommended by

Assignee

Paul Meems

Reporter

Paul Meems

Labels

None

Epic Link

Affects versions

Fix versions

Priority

Medium
Configure