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

Re: [RFC PATCH v4 03/26] pkt-line: Make packet_read_line easier to debug

From
Jeff King <peff@peff.net>
Date
Oct 30, 2009, 19:30 UTC
Message-ID
<20091030193030.GA10985@coredump.intra.peff.net>
In-Reply-To
<20091030191239.GF10505@spearce.org>
On Fri, Oct 30, 2009 at 12:12:40PM -0700, Shawn O. Pearce wrote:
Show 7 quoted lines
> > I am just a bystander, so maybe my opinion is not worth anything, but
> > personally I think you are obfuscating the code to save a single line.
> 
> Yup, me too.  But I'm also willing to do what I need to get my
> patches included in git.git.  Smart HTTP is something a lot of people
> have been waiting for.  If the maintainer wants the bikeshed to be
> a particular shade of red, I'll paint it that way.

Yes, I too want it merged ASAP, so please Junio if you disagree with my comments, ignore them. But I did want to point out that the proposed "improvement" was making things worse, IMHO. So I feel like I was at least bikeshedding his bikeshed, instead of starting my own. ;)

Show 8 quoted lines
> > If you really just want to initialize to zero, using
> > 
> >   char linelen[5] = { 0 };
> 
> Bleh, I find that has hard to grok as what we have now.  Perhaps my
> understanding of the relevant standards is incomplete, but I'd read
> that as linelen[0] = 0, but the other 4 positions are undefined
> and may be not be initialized.
Your understanding is incomplete. :) C99, 6.7.8, paragraph 19:
  ... all subobjects that are not initialized explicitly shall be
  initialized implicitly the same as objects that have static storage
  duration.
I don't recall offhand whether that was the case in C89 or not.

But that being said, it was an attempt to make the meaning clear. If it's not to you (who I consider at least reasonably competent ;) ), then it failed.

Show 8 quoted lines
> >   die("protocol error: bad line length character: %.4s", linelen);
> 
> I actually considered this one, but again I wasn't clear what would
> happen in the standard C library when we fed a string that wasn't
> actually NUL terminated.  Is the library permitted to call strlen()
> before formatting?  If so strlen() could SIGSEGV if we are unlucky
> and no NUL is present between our string and the end of the assigned
> memory region.

No, using a precision specifier for a string with no NUL is explicitly allowed by the standard (and we use it elsewhere in git, IIRC).

Show 7 quoted lines
> To me, my original version was the most clear, to me and anyone
> else who could ever possibly come by to read it.  The "one extra
> line of code" is also only in an error condition which never occurs
> (but did once due to a bug in the HTTP code, which is why I added
> this patch to my series, to help debug it).  Its not like this is
> a performance sensitive section of git that Linus is going to come
> back and overhaul.

Heh. You never know what performance item Linus will complain about. ;) But yes, I am fine with your initial one, too. The drawback to it (and my "%.4s") is not that one line of code is so unbearable, but that it is one extra thing anyone using it as a string must do, and if they forget, we get a horrible segfault.

Anyway, my complaint has been lodged. Junio is aware of the alternatives and can pick whichever he wants.

-Peff
Previous: Shawn O. PearceNext: David Brown
Message 11 of 60 in “Return of smart HTTP”
  1. 00/26 Return of smart HTTPShawn O. Pearce, Oct 29, 2009
  2. 01/26 http-push: fix check condition on http.c::finish_http_pack_request()Shawn O. Pearce, Oct 29, 2009
  3. 02/26 pkt-line: Add strbuf based functionsShawn O. Pearce, Oct 29, 2009
  4. 03/26 pkt-line: Make packet_read_line easier to debugShawn O. Pearce, Oct 29, 2009
  5. Junio C HamanoOct 29, 2009
  6. Shawn O. PearceOct 29, 2009
  7. Junio C HamanoOct 29, 2009
  8. Shawn O. PearceOct 29, 2009
  9. Jeff KingOct 30, 2009
  10. Shawn O. PearceOct 30, 2009
  11. Jeff KingOct 30, 2009
  12. David BrownOct 30, 2009
  13. Junio C HamanoOct 30, 2009
  14. 04/26 fetch-pack: Use a strbuf to compose the want listShawn O. Pearce, Oct 29, 2009
  15. 05/26 Move "get_ack()" back to fetch-packShawn O. Pearce, Oct 29, 2009
  16. Junio C HamanoOct 29, 2009
  17. Shawn O. PearceOct 29, 2009
  18. 06/26 Add multi_ack_detailed capability to fetch-pack/upload-packShawn O. Pearce, Oct 29, 2009
  19. Junio C HamanoOct 29, 2009
  20. Shawn O. PearceOct 29, 2009
  21. 07/26 remote-curl: Refactor walker initializationShawn O. Pearce, Oct 29, 2009
  22. 08/26 fetch: Allow transport -v -v -v to set verbosity to 3Shawn O. Pearce, Oct 29, 2009
  23. 09/26 remote-helpers: Fetch more than one ref in a batchShawn O. Pearce, Oct 29, 2009
  24. 10/26 remote-helpers: Support custom transport optionsShawn O. Pearce, Oct 29, 2009
  25. 11/26 Move WebDAV HTTP push under remote-curlShawn O. Pearce, Oct 29, 2009
  26. Tay Ray ChuanOct 30, 2009
  27. Shawn O. PearceOct 31, 2009
  28. Tay Ray ChuanOct 30, 2009
  29. Clemens BuchacherOct 30, 2009
  30. Tay Ray ChuanOct 30, 2009
  31. 12/26 remote-helpers: return successfully if everything up-to-dateShawn O. Pearce, Oct 29, 2009
  32. 13/26 Git-aware CGI to provide dumb HTTP transportShawn O. Pearce, Oct 29, 2009
  33. 14/26 Add stateless RPC options to upload-pack, receive-packShawn O. Pearce, Oct 29, 2009
  34. Junio C HamanoOct 29, 2009
  35. Shawn O. PearceOct 29, 2009
  36. Junio C HamanoOct 29, 2009
  37. Shawn O. PearceOct 30, 2009
  38. 15/26 Smart fetch and push over HTTP: server sideShawn O. Pearce, Oct 29, 2009
  39. 16/26 http-backend: add GIT_PROJECT_ROOT environment varShawn O. Pearce, Oct 29, 2009
  40. 17/26 http-backend: reword some documentationShawn O. Pearce, Oct 29, 2009
  41. 18/26 http-backend: use mod_alias instead of mod_rewriteShawn O. Pearce, Oct 29, 2009
  42. 19/26 http-backend: add example for gitweb on same URLShawn O. Pearce, Oct 29, 2009
  43. 20/26 http-backend: more explict LocationMatchShawn O. Pearce, Oct 29, 2009
  44. 21/26 Discover refs via smart HTTP server when availableShawn O. Pearce, Oct 29, 2009
  45. 22/26 Smart push over HTTP: client sideShawn O. Pearce, Oct 29, 2009
  46. 23/26 Smart fetch over HTTP: client sideShawn O. Pearce, Oct 29, 2009
  47. 24/26 Smart HTTP fetch: gzip requestsShawn O. Pearce, Oct 29, 2009
  48. 25/26 t5540-http-push: remove redundant fetchesShawn O. Pearce, Oct 29, 2009
  49. 26/26 test smart http fetch and pushShawn O. Pearce, Oct 29, 2009
  50. Clemens BuchacherOct 29, 2009
  51. Shawn O. PearceOct 29, 2009
  52. Junio C HamanoOct 29, 2009
  53. Shawn O. PearceOct 29, 2009
  54. Shawn O. PearceOct 29, 2009
  55. Junio C HamanoOct 30, 2009
  56. Shawn O. PearceOct 30, 2009
  57. Tay Ray ChuanOct 30, 2009
  58. Shawn O. PearceOct 31, 2009
  59. Jakub NarebskiOct 29, 2009
  60. Shawn O. PearceOct 29, 2009

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.