git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add git-imap-send.

From
Linus Torvalds <torvalds@osdl.org>
Date
Mar 9, 2006, 18:21 UTC
Message-ID
<Pine.LNX.4.64.0603091017530.18022@g5.osdl.org>
In-Reply-To
<7vmzfz5w2k.fsf@assigned-by-dhcp.cox.net>
On Thu, 9 Mar 2006, Junio C Hamano wrote:
Show 13 quoted lines
>
> Linus Torvalds <torvalds@osdl.org> writes:
> 
> > it's entirely possible that it will load bytes from "string" _past_ the 
> > end of the string because of an unrolled inner loop that does things 
> > multiple bytes at a time. They won't be used in the eventual result, but 
> > just the fact that they are loaded from memory can mean that your program 
> > takes a SIGSEGV, for example, becaue it turns out "string" was just a 
> > single NUL byte at the end of a page, and there's nothing after it.
> 
> Funny.  I've seen this exact bug in memcmp and strcmp in earlier
> SunOS (pre Solaris) libc when I was working on something like
> Valgrind in my previous life.
Well, Valgrind actually can complain for no good reason.

System libraries often take advantage of knowing how the CPU and the system memory layout works. For example, just from knowing that pages are always aligned to a certain (largish) boundary, you can know that it's perfectly safe to do certain optimizations and prefetch past the end of an object, as long as it's in the same page (and the easiest way to verify that is to just do it when something is aligned).

So Valgrind will sometimes complain about perfectly bug-free code, just because the bug-free code accesses outside the "strictly allowable" region because it knows it can.

Valgrind can be taught about system libraries like that, but especially if it's an early port to a new architecture or OS, valgrind will often complain unnecessarily.

			Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 13 in “Add git-imap-send.”
  1. Add git-imap-send.Mike McCormack, Mar 6, 2006
  2. Junio C HamanoMar 9, 2006
  3. Johannes SchindelinMar 9, 2006
  4. Andreas EricssonMar 9, 2006
  5. Johannes SchindelinMar 9, 2006
  6. Mark WoodingMar 9, 2006
  7. Johannes SchindelinMar 9, 2006
  8. Mark WoodingMar 10, 2006
  9. Linus TorvaldsMar 9, 2006
  10. Junio C HamanoMar 9, 2006
  11. Linus TorvaldsMar 9, 2006
  12. Junio C HamanoMar 9, 2006
  13. Mike McCormackMar 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.