h2o / h2o/picohttpparser

Dead / duplicated code in `is_complete()`

Open
#61 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
2.1k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

Hi

I'm going through the code in order to educate myself on how these parsers work, and I think I've noticed some dead code in `is_complete` function:

https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L221-L223

The `while` loop above can only terminate from:
- `CHECK_EOF` in [line 206](https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L206): https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L55-L59
- `EXPECT_CHAR`, one line below, in [line 207](https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L207):
https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L61-L69
- Return statement in [line 217](https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L217): https://github.com/h2o/picohttpparser/blob/81fe3d99fd90a55cafb993e53fd3000dbc4d564c/picohttpparser.c#L217

Is this really unreachable or am I missing something? Is there a reason for this code to be there?

Also, given that `EXPECT_CHAR` already contains `CHECK_EOF`, and `CHECK_EOF` doesn't mutate any state, line 207 duplicates line 206, making the routine check for EOF twice in a row, when `*buf == ''`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in picohttpparser.c at the is_complete() control flow around lines 206-223, then inspect the CHECK_EOF and EXPECT_CHAR macros at the referenced lines. Confirm whether the reported branch is unreachable and whether the consecutive EOF checks are redundant; done means the dead or duplicated logic is removed or justified without changing parser behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.