fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers.git
Log | Files | Refs | README | LICENSE

select.h (1704B)


      1 /*
      2  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
      3  *
      4  * Permission to use, copy, modify, and/or distribute this software for any
      5  * purpose with or without fee is hereby granted.
      6  *
      7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     10  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     12  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     13  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     14  */
     15 
     16 #ifndef _FORTIFY_SYS_SELECT_H
     17 #define _FORTIFY_SYS_SELECT_H
     18 
     19 #ifndef __cplusplus
     20 __extension__
     21 #endif
     22 #include_next <sys/select.h>
     23 
     24 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
     25 
     26 #ifdef __cplusplus
     27 extern "C" {
     28 #endif
     29 
     30 static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
     31 void __fortify_FD_CLR(int __f, fd_set *__s)
     32 {
     33 	size_t __b = __builtin_object_size(__s, 0);
     34 
     35 	if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
     36 		__builtin_trap();
     37 	FD_CLR(__f, __s);
     38 }
     39 
     40 static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
     41 void __fortify_FD_SET(int __f, fd_set *__s)
     42 {
     43 	size_t __b = __builtin_object_size(__s, 0);
     44 
     45 	if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set))
     46 		__builtin_trap();
     47 	FD_SET(__f, __s);
     48 }
     49 
     50 #undef FD_CLR
     51 #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set)
     52 #undef FD_SET
     53 #define FD_SET(fd, set) __fortify_FD_SET(fd, set)
     54 
     55 #ifdef __cplusplus
     56 }
     57 #endif
     58 
     59 #endif
     60 
     61 #endif