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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...