Skip to content

[FIX] networking.c: replace DEBUG_OUT integer toggle with CMake opt-in; fix error messages using printf() instead of fprintf(stderr)#2175

Open
Varadraj75 wants to merge 2 commits intoCCExtractor:masterfrom
Varadraj75:fix/networking-debug-out-and-stderr
Open

[FIX] networking.c: replace DEBUG_OUT integer toggle with CMake opt-in; fix error messages using printf() instead of fprintf(stderr)#2175
Varadraj75 wants to merge 2 commits intoCCExtractor:masterfrom
Varadraj75:fix/networking-debug-out-and-stderr

Conversation

@Varadraj75
Copy link
Contributor

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

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Summary

Fixes #2174 — two related bugs in src/lib_ccx/networking.c.

Fix 1 — Replace DEBUG_OUT integer toggle with CMake opt-in

#define DEBUG_OUT 0 caused debug code to always be compiled into
production builds, just silenced at runtime. This is the same pattern
fixed for VBI_DEBUG in #2168.

Removed the #define DEBUG_OUT 0 and replaced all #if DEBUG_OUT
guards with #ifdef NETWORKING_DEBUG, then added a proper CMake option:

option (NETWORKING_DEBUG "Enable networking debug output" OFF)

if (NETWORKING_DEBUG)
  add_definitions(-DNETWORKING_DEBUG)
  message(STATUS "Networking debug output enabled")
endif (NETWORKING_DEBUG)

Developers who need networking debug output can now opt in explicitly:

cmake .. -DNETWORKING_DEBUG=ON

Fix 2 — Replace printf() with fprintf(stderr) for error messages

Three error conditions were writing to stdout instead of stderr:

printf("Can't send BIN header\n");   // line 153
printf("Can't send BIN data\n");     // line 180
printf("Unable to send data\n");     // line 240

This means network errors are silently swallowed when stdout is
redirected, e.g. ccextractor input.ts > output.srt. All three
have been changed to fprintf(stderr, ...), consistent with the
rest of the error handling in the same file.

Testing

Built and verified locally on macOS with both NETWORKING_DEBUG=OFF
(default) and NETWORKING_DEBUG=ON. All existing CI tests pass.

Fixes #2174

…o fprintf(stderr)

- Remove #define DEBUG_OUT 0 from networking.c and replace all
  #if DEBUG_OUT guards with #ifdef NETWORKING_DEBUG, consistent
  with how other debug flags work in the codebase (see CCExtractor#2168)
- Add CMake option -DNETWORKING_DEBUG=ON for opt-in debug builds
- Replace 3 error messages using printf() with fprintf(stderr):
    'Can't send BIN header'
    'Can't send BIN data'
    'Unable to send data'
  Error output should go to stderr so it is visible when stdout
  is redirected (e.g. ccextractor input.ts > output.srt)

Fixes CCExtractor#2174
Copilot AI review requested due to automatic review settings March 4, 2026 23:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #2174 by making networking debug output an explicit CMake opt-in (instead of being always compiled) and by routing networking error messages to stderr.

Changes:

  • Replace DEBUG_OUT integer toggle with #ifdef NETWORKING_DEBUG in src/lib_ccx/networking.c.
  • Add a NETWORKING_DEBUG CMake option to enable networking debug output at compile time.
  • Switch several network send failure messages from printf() (stdout) to fprintf(stderr, ...) (stderr).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/lib_ccx/networking.c Gates debug logging behind NETWORKING_DEBUG and sends error messages to stderr.
src/CMakeLists.txt Introduces a CMake option/define to enable NETWORKING_DEBUG.
docs/CHANGES.TXT Adds a changelog entry for the fixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Fix %u -> %zu for size_t in Sending header and Sending EPG debug logs
- Fix %u -> %d for int in Sending bytes debug log
- Remove duplicate option(NETWORKING_DEBUG) and if(NETWORKING_DEBUG)
  blocks in CMakeLists.txt

Addresses Copilot review comments on CCExtractor#2175.
@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 f377be9...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 86/86
Teletext 21/21
WTV 13/13
XDS 34/34

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., 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 --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

All tests passed completely.

Check the result page for more info.

@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 f377be9...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 6/7
DVD 3/3
DVR-MS 2/2
General 25/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 80/86
Teletext 21/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...

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)

3 participants