<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 18, 2011, at 2:33 PM, Eli Friedman wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><blockquote type="cite">+// Warn if the user has made the 'size' argument to strlcpy or strlcat<br></blockquote><blockquote type="cite">+// be the size of the source, instead of the destination.<br></blockquote><blockquote type="cite">+void Sema::CheckStrlcpycatArguments(const CallExpr *Call,<br></blockquote><blockquote type="cite">+                                    IdentifierInfo *FnName) {<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  // Don't crash if the user has the wrong number of arguments<br></blockquote><blockquote type="cite">+  if (Call->getNumArgs() != 3)<br></blockquote><blockquote type="cite">+    return;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  const Expr *SrcArg = ignoreLiteralAdditions(Call->getArg(1), Context);<br></blockquote><blockquote type="cite">+  const Expr *SizeArg = ignoreLiteralAdditions(Call->getArg(2), Context);<br></blockquote><blockquote type="cite">+  const Expr *CompareWithSrc = NULL;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+  // Look for 'strlcpy(dst, x, sizeof(x))'<br></blockquote><blockquote type="cite">+  if (const Expr *Ex = getSizeOfExprArg(SizeArg))<br></blockquote><blockquote type="cite">+    CompareWithSrc = Ex;<br></blockquote><blockquote type="cite">+  else {<br></blockquote><blockquote type="cite">+    // Look for 'strlcpy(dst, x, strlen(x))'<br></blockquote><blockquote type="cite">+    if (const CallExpr *SizeCall = dyn_cast<CallExpr>(SizeArg)) {<br></blockquote><blockquote type="cite">+      if (SizeCall->isBuiltinCall(Context) == Builtin::BIstrlen<br></blockquote><blockquote type="cite">+          && SizeCall->getNumArgs() == 1)<br></blockquote><blockquote type="cite">+        CompareWithSrc = ignoreLiteralAdditions(SizeCall->getArg(0), Context);<br></blockquote><blockquote type="cite">+    }<br></blockquote><blockquote type="cite">+  }<br></blockquote><br>strlcpy(dst, x, strlen(foo)) is clearly wrong no matter what foo is;<br>should we warn unconditionally?<br></div></span></blockquote></div><br><div>Seems reasonable to me.</div></body></html>