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

Re: [PATCH 02/13] declare overflow during base128 decoding when 1 MSB nonzero, not 7

From
Junio C Hamano <junkio@cox.net>
Date
Apr 6, 2007, 00:29 UTC
Message-ID
<7vvegal506.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<56b7f5510704051608g4bf9ffb7t9f94b532c7a0ebdf@mail.gmail.com>
"Dana How" <danahow@gmail.com> writes:
> Concerning SEEK_SET,
> you are correct: my unistd.h #define's SEEK_SET to 0.

My understanding of the history is back when there was seek() but not lseek() nor SEEK_X macros, everybody passed bare integers and it was quite well established that 0 meant what SEEK_SET means now, so I would be quite surprised if there is _any_ platform that defines SEEK_SET to anything but zero.

Having said that, I wonder if this kind of thing can be caught with sparse. We should be able to express (or perhaps sparse could have a built-in rule that says) something like "although the standard says the third parameter to lseek() can be any integer, you should not use anything but SEEK_X preprocessor macros; also SEEK_X preprocessor macros, although they are typically just "#define"s of small integer literals, can never appear anywhere other than the third parameter as seek() and lseek()". I realize that there needs some data-flow analysis to allow a code like this, though:

	int move_to(int fd, ofs_t offset, int relative)
	{
		int whence = SEEK_SET;
	        if (relative) {
                	whence = SEEK_CUR;
	                offset += relative;
	        }
		return lseek(fd, offset, whence) != (off_t)-1;
	}
> But if someone edits this, the arg order might remain.
Very true, and that is why I said I am going to take the patch.
Previous: Dana HowNext: Nicolas Pitre
Message 4 of 6 in “declare overflow during base128 decoding when 1 MSB nonzero, not 7”
  1. 02/13 declare overflow during base128 decoding when 1 MSB nonzero, not 7Dana How, Apr 5, 2007
  2. Junio C HamanoApr 5, 2007
  3. Dana HowApr 5, 2007
  4. Junio C HamanoApr 6, 2007
  5. Nicolas PitreApr 6, 2007
  6. Nicolas PitreApr 6, 2007

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.