Intergral Type To Small For Pointer

  • Enterprise Edition
  • Version 8.9.10 (build 61524)

The C code looks like this:

if ((WCHAR)NULL != pdm->dmFormName[0])
{blah…}

The dmFormName array in the structure pointed to by pdm is declared like this:
WCHAR dmFormName[CCHFORMNAME];

I get a Code Smell like this:
An integral type is too small to hold a pointer value.

What the code is trying to do is to see if the first WCHAR of the array is a null terminator. I wouldn’t think that this is a rare occurrence. I could change the code to use a
wcsnlen_s to compare with 0 but I want to modify the source code as little as possible. It seems what is being done here is possible.

Hi,

Welcome to the community!

Would you mind sharing the rule key from this issue? It should be something like c:1234. I’m asking because I want to check Jira to see if any work has been done on the rule in question since the LTS.

 
Ann

Hi Ann!

The rule key looks like c:S1767 ( Pointers should not be cast to integral types) but that doesn’t make sense.

Thanks!
Dale

Hi Dale,

Thanks for this! Since this rule hasn’t been touched since the LTS, as far as I can tell, I’m referring the debate to the team.

 
:smiley:
Ann

Hi @DaleZ ,
From what I understand of your code, dmFormName doesn’t contain pointers but chars and what you are trying to test is whether the first char is 0, not whether it is a null pointer.
So I think what you want to test is

if ((WCHAR)0 != pdm->dmFormName[0])
{blah…}

Ah so “NULL” is treated as a pointer not a literal zero. I’ll try that change and let you know if it resolves the issue. If so then my mistake! :slight_smile:

I changed it to:

        ('\0' != pdm->dmFormName[0])

and it seems to work fine.

Thank you for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.