Snort mailing list archives

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


From: Joshua Kinard <kumba () gentoo org>
Date: Sun, 13 Apr 2014 16:20:17 -0400

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 () gentoo org
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

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Snort-devel mailing list
Snort-devel () lists sourceforge net
https://lists.sourceforge.net/lists/listinfo/snort-devel
Archive:
http://sourceforge.net/mailarchive/forum.php?forum_name=snort-devel

Please visit http://blog.snort.org for the latest news about Snort!


Current thread: