Jump to content

Runtime Checking: Remove Cast In Tex_Dds.cpp


Recommended Posts

Hi

Running test with runtimechecks enabled results in an error:

-------

Run-Time Check Failure #1 - A cast to a smaller data type has caused a loss of data. If this was intentional, you should mask the source of the cast with the appropriate bitmask. For example:

char c = (i & 0xFF);

Changing the code in this way will not affect the quality of the resulting optimized code.

-------

I've changed a few lines in tex_dds.cpp to work around the error.

Before:

	static inline size_t access_bit_tbl64(u64 tbl, size_t idx, size_t bit_width)
{
size_t val = (size_t)(tbl >> (idx*bit_width));
val &= bit_mask<u64>(bit_width);
return val;
}

After:

	static inline size_t access_bit_tbl64(u64 tbl, size_t idx, size_t bit_width)
{
size_t val = (tbl >> (idx*bit_width)) & bit_mask<u64>(bit_width);
return val;
}

or probably even:

	static inline size_t access_bit_tbl64(u64 tbl, size_t idx, size_t bit_width)
{
return (tbl >> (idx*bit_width)) & bit_mask<u64>(bit_width);
}

The same should most likely be done with the function access_bit_tbl.

It simply removes the need for a cast and makes it a bit less readable :D.

That's the only problem I've detected so far with runtimechecking.

What do you think? Is that right or did I miss something?

Edited by Yves
Link to comment
Share on other sites

Hi and thanks for looking into this!

I've just committed a fix based upon your first proposal (it's sometimes nice to have a separate local variable to display its value when debugging - more convenient than shift+F11 and adding a watch on RAX).

While at it, I've combined both functions into a template to avoid duplication.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...