WhiteSpaces in .splintrc preprocessor directive -D
Asked Answered
S

2

6

I want to run splint on some of my sources within a debian stable environment.
I need to give the preprocessor directive -DUINT16_T='unsigned short' and as I need that very often. I'd like to place it inside my .splintrc file.
When running from commandline like splint -DUINT16_T='unsigned short' mysource.c it is working well. If moving this line into my .splintrc file

-DUINT16_T='unsigned short'
-I/usr/local/include/

the splint call results in

Cannot list files in .splintrc files:
                                 short' (probable missing + or -)
  A flag is not recognized or used in an incorrect way (Use -badflag to inhibit
  warning)

Has anyone a solution? (No alias, please).

For furher discussion I'll offer a mnwe (minimal not working example) hello.c, which might help:

#include <stdio.h>

int main (void)
{
  UINT16_T returnvalue=0;
  printf ("Hello, world!\n");
  return returnvalue;
}

The command gcc -DUINT16_T='unsigned short' hello.c runs fine - and also does splint -DUINT16_T='unsigned short' hello.c which of course claims

Return value type unsigned short int does not match declared type
                 int: returnvalue

But again, how can I include this DEFINE into my .splintrc?

Supersedure answered 5/3, 2013 at 9:30 Comment(1)
I need the same thing, except for the flag: "-Dbit=unsigned char"Furnishing
K
1

--New answer--

What you are asking is just not implemented in splint.

If you look at the splint 3.1.2 rcfiles_loadFile function in rcfiles.c line 124

124          while ((c = *s) != '\0')
125             { /* remember to handle spaces and quotes in -D and -U ... */
126               if (escaped)
127                 {
128                   escaped = FALSE;
129                 }
130               else if (quoted)
131                 {
132                   if (c == '\\')
133                     {
134                       escaped = TRUE;
135                     }
136                   else if (c == '\"')
137                     {
138                       quoted = FALSE;
139                     }
140                   else
141                     {
142                       ;
143                     }
144                 }
145               else if (c == '\"')
146                 {
147                   quoted = TRUE;
148                 }
149               else
150                 {
151                  if (c == ' ' || c == '\t' || c == '\n')
152                    {
153                      /*@innerbreak@*/ break;
154                    }
155                }
156 
157               s++;
158               incColumn ();
159             }

You see that the comment in line 125 is a TODO for what you are asking.

I changed the line 151 to

151                  if (c == '\t' || c == '\n')

Compile, run and then your minimal not working example (without quotes in .splintrc) is passing the test without a problem.

However this modification is a bit rough since some splint unit tests are then failing.

Katharinekatharsis answered 24/7, 2014 at 12:22 Comment(1)
I tried - and your file runs fine - but try #include <stdio.h> int main (void) { UINT16_T returnvalue=0; printf ("Hello, world!\n"); return returnvalue; } then you'll see in only runs because the define is not used. So sad. Furhter hints/ideas?Supersedure
D
0

Use double quotes not single quotes.

-DUINT16_T="unsigned short"
Divergence answered 27/4, 2015 at 16:23 Comment(2)
At the moment I can not try, but having a look at the comment #15220728 I think also double quotes won't work.Supersedure
Quotes in that comment doesn't apply to .splintrc. As you can see from the source code string gets quoted with '\"' char.Divergence

© 2022 - 2024 — McMap. All rights reserved.