Skip to content

Fix networking.c debug flag and stderr routing#2212

Open
NexionisJake wants to merge 1 commit intoCCExtractor:masterfrom
NexionisJake:fix/networking-debug-stderr
Open

Fix networking.c debug flag and stderr routing#2212
NexionisJake wants to merge 1 commit intoCCExtractor:masterfrom
NexionisJake:fix/networking-debug-stderr

Conversation

@NexionisJake
Copy link

  • Remove #define DEBUG_OUT 0; replace all #if DEBUG_OUT guards with #ifdef NETWORKING_DEBUG for compile-time opt-in via
    -DNETWORKING_DEBUG=ON

    Fixes [BUG] networking.c: DEBUG_OUT uses integer toggle instead of CMake opt-in; error messages use printf() instead of fprintf(stderr) #2174

    In raising this pull request, I confirm the following (please check boxes):

    Reason for this PR:

    • This PR adds new functionality.
    • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample
      exists.
    • This PR is porting code from C to Rust.

    Sanity check:

    • I have read and understood the contributors
      guide
      .
    • I have checked that another pull request for this purpose does not exist.
    • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to
      the changelog.
    • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

    Repro instructions:

    Bug 1 — Error messages swallowed when stdout is redirected

    Run CCExtractor in networked/TCP mode and redirect stdout:

    ccextractor input.ts -tcp 2048 > output.srt                                                                              
    If the TCP send fails (e.g. server not running), the error messages                                                      
    "Can't send BIN header", "Can't send BIN data", and "Unable to send data"                                                
    were written to stdout and thus silently swallowed by the redirect. After this                                           
    fix they go to stderr and are always visible.                                                                            
                                                                                                                             
    Bug 2 — DEBUG_OUT integer toggle leaves dead debug code in production builds                                             
                                                                                                                             
    Before this fix, #define DEBUG_OUT 0 meant the debug blocks were compiled                                                
    out by the preprocessor but the macro still existed. Setting it to 1 in                                                  
    source was the only way to enable debug output, requiring a source edit.                                                 
    After this fix, pass -DNETWORKING_DEBUG=ON to cmake to opt in:                                                           
    cmake ../src -DNETWORKING_DEBUG=ON                                                                                       
    make -j$(nproc)                                                                                                          
    Default builds (NETWORKING_DEBUG=OFF) produce zero debug output and zero                                                 
    additional warnings. This is consistent with how VBI_DEBUG was handled in                                                
    #2168.                                                                                                                   
                                                                                                                             
    Bug 3 — -Wformat UB in debug log format specifiers                                                                       
                                                                                                                             
    PR #2175 attempted to address #2174 but was not merged because it left %u                                                
    used with size_t and int variables inside debug blocks, which is undefined                                               
    behaviour under -Wformat. This PR fixes each call site:                                                                  
    - net_send_header: len is size_t → %zu                                                                                   
    - net_send_cc: len is int → %d                                                                                           
    - net_send_epg: len is size_t → %zu                                                                                      
                                                                                                                             
    Both NETWORKING_DEBUG=OFF and NETWORKING_DEBUG=ON builds were verified                                                   
    to produce zero new warnings.                                                                                            

- Remove #define DEBUG_OUT 0; replace all #if DEBUG_OUT guards with
  #ifdef NETWORKING_DEBUG for compile-time opt-in via -DNETWORKING_DEBUG=ON
- Fix three error messages using printf() to use fprintf(stderr):
    "Can't send BIN header", "Can't send BIN data", "Unable to send data"
- Fix format specifiers in debug logs: %zu for size_t, %d for int
  (resolves -Wformat UB flagged in PR CCExtractor#2175 review)
- Add NETWORKING_DEBUG CMake option to CMakeLists.txt (single definition)

Fixes CCExtractor#2174

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 03ad9e8...:
Report Name Tests Passed
Broken 10/13
CEA-708 1/14
DVB 3/7
DVD 3/3
DVR-MS 2/2
General 25/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 75/86
Teletext 20/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65...
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b...
  • ccextractor --out=spupng c83f765c66...
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 8e8229b88b..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 132d7df7e9..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 99e5eaafdc..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 b22260d065..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 7aad20907e..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 01509e4d27..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --xds --latin1 --ucla 85058ad37e..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --ucla b22260d065..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 7f41299cc7..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 03ad9e8...:
Report Name Tests Passed
Broken 10/13
CEA-708 1/14
DVB 4/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 79/86
Teletext 20/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 8e8229b88b..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 132d7df7e9..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 99e5eaafdc..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 b22260d065..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla 7aad20907e..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 01509e4d27..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --xds --latin1 --ucla 85058ad37e..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --ucla b22260d065..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla --xds 7f41299cc7..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] networking.c: DEBUG_OUT uses integer toggle instead of CMake opt-in; error messages use printf() instead of fprintf(stderr)

2 participants