OSDN Git Service

fix broken checkin, test should be link not assemble
[pf3gnuchains/gcc-fork.git] / libmudflap / mf-hooks2.c
index 5a001ad..5649e1c 100644 (file)
@@ -1,5 +1,5 @@
 /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
-   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2009 Free Software Foundation, Inc.
    Contributed by Frank Ch. Eigler <fche@redhat.com>
    and Graydon Hoare <graydon@redhat.com>
 
@@ -7,28 +7,22 @@ This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
-In addition to the permissions in the GNU General Public License, the
-Free Software Foundation gives you unlimited permission to link the
-compiled version of this file into combinations with other programs,
-and to distribute those combinations without any restriction coming
-from the use of this file.  (The General Public License restrictions
-do apply in other respects; for example, they cover modification of
-the file, and distribution when not linked into a combine
-executable.)
-
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
 WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
 
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 
@@ -41,7 +35,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #if !defined(__FreeBSD__) && !defined(__APPLE__)
 #define _POSIX_SOURCE
 #endif /* Some BSDs break <sys/socket.h> if this is defined. */
-#define _GNU_SOURCE 
+#define _GNU_SOURCE
 #define _XOPEN_SOURCE
 #define _BSD_TYPES
 #define __EXTENSIONS__
@@ -192,7 +186,7 @@ WRAPPER2(char *, strcpy, char *dest, const char *src)
 
   size_t n = strlen (src);
   TRACE ("%s\n", __PRETTY_FUNCTION__);
-  MF_VALIDATE_EXTENT(src, CLAMPADD(n, 1), __MF_CHECK_READ, "strcpy src"); 
+  MF_VALIDATE_EXTENT(src, CLAMPADD(n, 1), __MF_CHECK_READ, "strcpy src");
   MF_VALIDATE_EXTENT(dest, CLAMPADD(n, 1), __MF_CHECK_WRITE, "strcpy dest");
   return strcpy (dest, src);
 }
@@ -216,7 +210,7 @@ WRAPPER2(char *, strcat, char *dest, const char *src)
   size_t src_sz;
   TRACE ("%s\n", __PRETTY_FUNCTION__);
   dest_sz = strlen (dest);
-  src_sz = strlen (src);  
+  src_sz = strlen (src);
   MF_VALIDATE_EXTENT(src, CLAMPADD(src_sz, 1), __MF_CHECK_READ, "strcat src");
   MF_VALIDATE_EXTENT(dest, CLAMPADD(dest_sz, CLAMPADD(src_sz, 1)),
                     __MF_CHECK_WRITE, "strcat dest");
@@ -228,15 +222,15 @@ WRAPPER2(char *, strncat, char *dest, const char *src, size_t n)
 {
 
   /* nb: validating the extents (s,n) might be a mistake for two reasons.
-     
-  (1) the string s might be shorter than n chars, and n is just a 
+
+  (1) the string s might be shorter than n chars, and n is just a
   poor choice by the programmer. this is not a "true" error in the
   sense that the call to strncat would still be ok.
-  
+
   (2) we could try to compensate for case (1) by calling strlen(s) and
   using that as a bound for the extent to verify, but strlen might fall off
   the end of a non-terminated string, leading to a false positive.
-  
+
   so we will call strnlen(s,n) and use that as a bound.
 
   if strnlen returns a length beyond the end of the registered extent
@@ -265,7 +259,7 @@ WRAPPER2(int, strcmp, const char *s1, const char *s2)
   size_t s2_sz;
   TRACE ("%s\n", __PRETTY_FUNCTION__);
   s1_sz = strlen (s1);
-  s2_sz = strlen (s2);  
+  s2_sz = strlen (s2);
   MF_VALIDATE_EXTENT(s1, CLAMPADD(s1_sz, 1), __MF_CHECK_READ, "strcmp 1st arg");
   MF_VALIDATE_EXTENT(s2, CLAMPADD(s2_sz, 1), __MF_CHECK_WRITE, "strcmp 2nd arg");
   return strcmp (s1, s2);
@@ -278,7 +272,7 @@ WRAPPER2(int, strcasecmp, const char *s1, const char *s2)
   size_t s2_sz;
   TRACE ("%s\n", __PRETTY_FUNCTION__);
   s1_sz = strlen (s1);
-  s2_sz = strlen (s2);  
+  s2_sz = strlen (s2);
   MF_VALIDATE_EXTENT(s1, CLAMPADD(s1_sz, 1), __MF_CHECK_READ, "strcasecmp 1st arg");
   MF_VALIDATE_EXTENT(s2, CLAMPADD(s2_sz, 1), __MF_CHECK_READ, "strcasecmp 2nd arg");
   return strcasecmp (s1, s2);
@@ -318,7 +312,7 @@ WRAPPER2(char *, strdup, const char *s)
   size_t n = strlen (s);
   TRACE ("%s\n", __PRETTY_FUNCTION__);
   MF_VALIDATE_EXTENT(s, CLAMPADD(n,1), __MF_CHECK_READ, "strdup region");
-  result = (char *)CALL_REAL(malloc, 
+  result = (char *)CALL_REAL(malloc,
                             CLAMPADD(CLAMPADD(n,1),
                                      CLAMPADD(__mf_opts.crumple_zone,
                                               __mf_opts.crumple_zone)));
@@ -343,11 +337,11 @@ WRAPPER2(char *, strndup, const char *s, size_t n)
   MF_VALIDATE_EXTENT(s, sz, __MF_CHECK_READ, "strndup region"); /* nb: strNdup */
 
   /* note: strndup still adds a \0, even with the N limit! */
-  result = (char *)CALL_REAL(malloc, 
+  result = (char *)CALL_REAL(malloc,
                             CLAMPADD(CLAMPADD(n,1),
                                      CLAMPADD(__mf_opts.crumple_zone,
                                               __mf_opts.crumple_zone)));
-  
+
   if (UNLIKELY(! result)) return result;
 
   result += __mf_opts.crumple_zone;
@@ -393,7 +387,7 @@ WRAPPER2(char *, strstr, const char *haystack, const char *needle)
 
 
 #ifdef HAVE_MEMMEM
-WRAPPER2(void *, memmem, 
+WRAPPER2(void *, memmem,
        const void *haystack, size_t haystacklen,
        const void *needle, size_t needlelen)
 {
@@ -544,8 +538,14 @@ WRAPPER2(struct tm*, gmtime, const time_t *timep)
 /* The following indicate if the result of the corresponding function
  * should be explicitly un/registered by the wrapper
 */
+
+#ifdef __FreeBSD__
+#define MF_REGISTER_fopen              __MF_TYPE_STATIC
+#else
 #undef  MF_REGISTER_fopen
+#endif
 #define MF_RESULT_SIZE_fopen           (sizeof (FILE))
+
 #undef  MF_REGISTER_opendir
 #define MF_RESULT_SIZE_opendir         0       /* (sizeof (DIR)) */
 #undef  MF_REGISTER_readdir
@@ -1394,7 +1394,8 @@ WRAPPER2(int, getsockopt, int s, int level, int optname, void *optval,
 WRAPPER2(int, accept, int s, struct  sockaddr *addr, socklen_t *addrlen)
 {
   TRACE ("%s\n", __PRETTY_FUNCTION__);
-  MF_VALIDATE_EXTENT (addr, (size_t)*addrlen, __MF_CHECK_WRITE, "accept addr");
+  if (addr != NULL)
+    MF_VALIDATE_EXTENT (addr, (size_t)*addrlen, __MF_CHECK_WRITE, "accept addr");
   return accept (s, addr, addrlen);
 }