Jeff King <peff@xxxxxxxx> writes: > On Mon, Dec 12, 2022 at 12:59:55PM -0800, Jonathan Tan wrote: > > > > And possibly put a comment above open_loose_object() that "path" > > > is only guaranteed to point to something sensible when a non-negative > > > value is returned. > > > > Junio made a point that there could, for example, be no path when the > > odb list is empty (maybe in the future) so I don't think this would be > > sufficient. But there is already a comment there pointing to a comment > > in another function that states "path ... (if any)" so this is something > > that callers should already take care of. In my changes, I'll initialize > > it to NULL and whenever I use it, I'll check for non-NULL first. > > If we return a non-negative value, then we opened something, so by > definition, don't we have a path of the thing we opened? > > I think the case Junio mentioned was if we for some reason didn't look > at _any_ path. In which case we'd be returning an error. Ah, my reading comprehension is failing me, sorry. We do want "path" to point to something sensible (well, whenever we can) when an error occurs, though, since we want to include that path in our error message when DIE_IF_CORRUPT is used. So guaranteeing "path" when a non-negative value is returned (and hence, no error occurred) is not so useful.