[Snort-devel] [SNORT-DEVEL] modification to switch()/case in snprintf.c for NetVI

Joshua Kinard kumba at ...2185...
Sun Apr 13 16:20:17 EDT 2014


On 04/13/2014 15:27, Bill Parker wrote:
> Hello All,
> 
>     In reviewing some code in NetVI, directory 'src', file 'snprintf.c'
> I found a rather lengthy switch()/case workup consisting of the following:
> 
>                     case '1':
>                     case '2':
>                     case '3':
>                     case '4':
>                     case '5':
>                     case '6':
>                     case '7':
>                     case '8':
>                     case '9':
> 
> Which could be written as:
> 
>                     case '1' ... '9':
> 
> since ASCII values for '1' thru '9' are in order in the ASCII
> table.  The patch file which modifies this is below:
> 
> --- snprintf.c.orig     2014-04-10 04:39:57.132977816 -0700
> +++ snprintf.c  2014-04-10 04:40:45.194086136 -0700
> @@ -174,15 +174,7 @@
>                      case '-': ljust = 1; goto nextch;
>                      case '0': /* set zero padding if len not set */
>                          if(len==0 && !pointflag) zpad = '0';
> -                    case '1':
> -                    case '2':
> -                    case '3':
> -                    case '4':
> -                    case '5':
> -                    case '6':
> -                    case '7':
> -                    case '8':
> -                    case '9':
> +                    case '1' ... '9':
>                          if(pointflag)
>                              maxwidth = maxwidth*10 + ch - '0';
>                          else
> 
> Would this be of any use in NetVI and/or Snort/DAQ?
> 
> Bill Parker (wp02855 at gmail dot com)
> 

I think this is more of a semantic/readability change than anything
functional.  The '...' syntax is also a non-standard C/C++ extension and not
widely known about (I actually discovered it myself about a month or so
ago).  I don't know how many compilers actually support it.  gcc introduced
it, so I assume clang supports it, but older compilers might not (Sun
Studio, MIPSPro, etc).  icc?

See:
https://stackoverflow.com/a/5924692/
https://stackoverflow.com/a/5327975/

-- 
Joshua Kinard
Gentoo/MIPS
kumba at ...2185...
4096R/D25D95E3 2011-03-28

"The past tempts us, the present confuses us, the future frightens us.  And
our lives slip away, moment by moment, lost in that vast, terrible in-between."

--Emperor Turhan, Centauri Republic




More information about the Snort-devel mailing list