On Fri, Aug 17, 2012 at 02:52:34PM +0200, Florian Weimer wrote:
> >+    {
> >+    case BUILT_IN_STRNCMP:
> >+    case BUILT_IN_STRNCASECMP:
> >+    case BUILT_IN_STRNCPY:
> >+    case BUILT_IN_STRNCAT:
> >+      strop = true;
> >+      /* FALLTHRU */
> >+    case BUILT_IN_MEMCPY:
> >+    case BUILT_IN_MEMMOVE:
> >+    case BUILT_IN_MEMCMP:
> >+      if (VEC_length (tree, params) < 3)
> >+    return;
> >+      src = VEC_index (tree, params, 1);
> >+      dest = VEC_index (tree, params, 0);
> >+      break;
> >+    case BUILT_IN_MEMSET:
> >+      if (VEC_length (tree, params) < 3)
> >+    return;
> >+      dest = VEC_index (tree, params, 0);
> >+      break;
> >+    case BUILT_IN_STRNDUP:
> >+      src = VEC_index (tree, params, 0);
> >+      strop = true;
> >+      break;
> >+    default:
> >+      break;
> >+    }
> 
> I think this would apply to memchr, snprintf, vsnprintf, stpncopy,
> bzero, bcopy, bcmp as well.  Or are some of them already lowered at
> this point?

s/stpncopy/stpncpy/, yeah, I guess, we could do that for those too,
but 1) I'd prefer to wait for the C++ FE change to go in first
2) {,v}snprintf would be much harder than the rest, as the size
argument then isn't the last argument to the function, and the FEs
only provide the last one right now.  The parser routine which parses
arguments doesn't know which fn it will be for, recording sizeof_arg
(including location_t) for all arguments would be an overkill,
perhaps we could record instead the first sizeof argument + its position in
the argument list.  That would not catch say
memset (ptr, sizeof (int), sizeof (ptr));
(as it would record 2nd argument, expr int and locus), but perhaps it is so
rare to use sizeof on second argument of memset that it doesn't matter.
On the other side it would help if somebody calls __builtin___memset_chk
and similar explicitly (sizeof in that case isn't the last argument, but
3rd), the above switch then could handle also BUILT_IN_*CHK.
That said, usually -D_FORTIFY_SOURCE is done through the string.h
wrapper inlines and that is handled already (and tested in the testcases).

        Jakub

Reply via email to