Use the correct CURLOPT_WRITEFUNCTION signature#21265
Closed
TedLyngmo wants to merge 1 commit intocurl:masterfrom
Closed
Use the correct CURLOPT_WRITEFUNCTION signature#21265TedLyngmo wants to merge 1 commit intocurl:masterfrom
TedLyngmo wants to merge 1 commit intocurl:masterfrom
Conversation
In order to not encourage users to use incompatible function pointers, change the callback function definitions to use `char *` instead of `void *` for the first argument. Triggered by https://stackoverflow.com/questions/79921871/curl-c-c-library-based-application-produces-erronious-response-for-http-post-r#comment141032037_79921871 : "The code was mostly modified from [this example code](https://curl.se/libcurl/c/postinmemory.html), honestly I never knew this is wrong. Thanks for pointing it out." Signed-off-by: Ted Lyngmo <ted@lyncon.se>
5304be6 to
c54fd46
Compare
bagder
approved these changes
Apr 8, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates libcurl tests and documentation/examples to use the canonical CURLOPT_WRITEFUNCTION callback prototype, aligning with curl_write_callback in the public headers and reducing the chance of users copying incompatible function pointer signatures.
Changes:
- Update write callback prototypes from
void *tochar *for the first argument in docs/examples. - Adjust a libtest write callback to match the correct callback signature.
- Update tutorial/FAQ text to reflect the correct prototype for user callbacks.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/libtest/lib3102.c | Makes the test write callback match libcurl’s curl_write_callback signature. |
| docs/libcurl/opts/CURLINFO_TLS_SSL_PTR.md | Fixes the example write callback signature to use char *. |
| docs/libcurl/libcurl-tutorial.md | Updates the documented write callback prototype (including the C++ example). |
| docs/FAQ.md | Updates the C++ callback example signature. |
| docs/examples/usercertinmem.c | Corrects example write callback signature. |
| docs/examples/url2file.c | Corrects example write callback signature. |
| docs/examples/synctime.c | Corrects example write callback signature. |
| docs/examples/sftpget.c | Corrects example write callback signature. |
| docs/examples/sessioninfo.c | Corrects example write callback signature. |
| docs/examples/sepheaders.c | Corrects example write callback signature. |
| docs/examples/postinmemory.c | Corrects example write callback signature. |
| docs/examples/http2-pushinmemory.c | Corrects example write callback signature. |
| docs/examples/hiperfifo.c | Corrects example write callback signature. |
| docs/examples/ghiper.c | Corrects example write callback signature. |
| docs/examples/getinmemory.c | Corrects example write callback signature. |
| docs/examples/ftpuploadresume.c | Corrects example write callback signature. |
| docs/examples/ftpsget.c | Corrects example write callback signature. |
| docs/examples/ftpget.c | Corrects example write callback signature. |
| docs/examples/ftp-delete.c | Corrects example write callback signature. |
| docs/examples/externalsocket.c | Corrects example write callback signature. |
| docs/examples/evhiperfifo.c | Corrects example write callback signature. |
| docs/examples/ephiperfifo.c | Corrects example write callback signature. |
| docs/examples/crawler.c | Corrects example write callback signature. |
| docs/examples/chkspeed.c | Corrects example write callback signature. |
| docs/examples/certinfo.c | Corrects example write callback signature. |
| docs/examples/cacertinmem.c | Corrects example write callback signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment was marked as off-topic.
This comment was marked as off-topic.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In order to not encourage users to use incompatible function pointers, change the callback function definitions to use
char *instead ofvoid *for the first argument.Triggered by https://stackoverflow.com/questions/79921871/curl-c-c-library-based-application-produces-erronious-response-for-http-post-r#comment141032037_79921871 :
"The code was mostly modified from this example code, honestly I never knew this is wrong. Thanks for pointing it out."