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

Re: undefined behavior in unit tests, was Re: [PATCH v3 3/3] reftable: prevent 'update_index' changes after adding records

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 3, 2025, 05:41 UTC
Message-ID
<Z6BW7_aj4C7B-g9P@pks.im>
In-Reply-To
<425859d1-d42e-42ee-b59c-723a519f0ad8@gmail.com>
On Sat, Feb 01, 2025 at 10:33:13AM +0000, Phillip Wood wrote:
Show 36 quoted lines
> Hi Peff
> 
> On 01/02/2025 02:24, Jeff King wrote:
> > On Wed, Jan 22, 2025 at 06:35:49AM +0100, Karthik Nayak wrote:
> > 
> > Coverity complains that this function may have undefined behavior. It's
> > an issue we have in a lot of other tests that have moved to the
> > unit-test framework. I've mostly been ignoring it, but this is a pretty
> > straight-forward example, so I thought I'd write a note.
> > 
> > The issue is that reftable_new_stack() might fail, leaving "st" as NULL.
> > And then we feed it to reftable_stack_new_addition(), which dereferences
> > it.
> > 
> > In normal production code, we'd expect something like:
> > 
> >    if (err)
> > 	return -1;
> > 
> > to avoid running the rest of the function after the first error. But the
> > test harness check() function doesn't return. It just complains to
> > stdout and keeps running!
> 
> That is to allow the test to add more context with test_msg() or do things
> like check all the members of a struct before returning. It is a bug in the
> test if it does not return after finding a NULL pointer, the correct usage
> is
> 
> 	if (!check(ptr))
> 		return;
> 
> As we're in the process of switching to using clar which does exit the text
> function if a check fails (that means there may be leaks on failure but if
> the test is failing then I don't think we should be worrying about leaks) I
> don't know if it is worth fixing these or not. I guess it depends if there
> are the list of targets for Seyi's Outreachy project.

Ah, yes, should've read your mail first, as you're saying basically the same as I did :)

Patrick
Previous: Phillip WoodNext: Junio C Hamano
Message 25 of 30 in “refs: small followups to the migration corruption fix”
  1. 0/3 refs: small followups to the migration corruption fixKarthik Nayak, Jan 17, 2025
  2. 1/3 refs: mark `ref_transaction_update_reflog()` as staticKarthik Nayak, Jan 17, 2025
  3. Patrick SteinhardtJan 17, 2025
  4. Karthik NayakJan 20, 2025
  5. 2/3 refs: use 'uint64_t' for 'ref_update.index'Karthik Nayak, Jan 17, 2025
  6. 3/3 reftable: prevent 'update_index' changes after header writeKarthik Nayak, Jan 17, 2025
  7. Patrick SteinhardtJan 17, 2025
  8. Karthik NayakJan 20, 2025
  9. Karthik NayakJan 20, 2025
  10. 0/3 refs: small followups to the migration corruption fixKarthik Nayak, Jan 21, 2025
  11. 1/3 refs: mark `ref_transaction_update_reflog()` as staticKarthik Nayak, Jan 21, 2025
  12. 2/3 refs: use 'uint64_t' for 'ref_update.index'Karthik Nayak, Jan 21, 2025
  13. 3/3 reftable: prevent 'update_index' changes after adding recordsKarthik Nayak, Jan 21, 2025
  14. Patrick SteinhardtJan 21, 2025
  15. Karthik NayakJan 21, 2025
  16. 0/3 refs: small followups to the migration corruption fixKarthik Nayak, Jan 22, 2025
  17. 1/3 refs: mark `ref_transaction_update_reflog()` as staticKarthik Nayak, Jan 22, 2025
  18. 2/3 refs: use 'uint64_t' for 'ref_update.index'Karthik Nayak, Jan 22, 2025
  19. 3/3 reftable: prevent 'update_index' changes after adding recordsKarthik Nayak, Jan 22, 2025
  20. Patrick SteinhardtJan 22, 2025
  21. Junio C HamanoJan 22, 2025
  22. Junio C HamanoJan 22, 2025
  23. undefined behavior in unit tests, was Re: [PATCH v3 3/3] reftable: prevent 'update_index' changes after adding recordsJeff King, Feb 1, 2025
  24. Phillip WoodFeb 1, 2025
  25. Patrick SteinhardtFeb 3, 2025
  26. Junio C HamanoFeb 3, 2025
  27. Jeff KingFeb 3, 2025
  28. Patrick SteinhardtFeb 3, 2025
  29. Karthik NayakFeb 3, 2025
  30. Jeff KingFeb 3, 2025

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.