Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x][v]aprintf(): Add APIs, and use them instead of [x][v]asprintf(3) #1168

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Jan 1, 2025

Cc: @stoeckmann


Revisions:

v2
  • tfix
$ git range-diff shadow/master gh/asprintf_ asprintf_ 
 1:  cb92c9bf =  1:  cb92c9bf lib/string/sprintf/: [v]aprintf(): Add functions
 2:  565dcd46 =  2:  565dcd46 lib/tcbfuncs.c: Split conditionals
 3:  fa55fb2f !  3:  dc720127 lib/, src/: Use aprintf() instead of asprintf(3)
    @@ lib/tcbfuncs.c: shadowtcb_status shadowtcb_move (/*@NULL@*/const char *user_newn
                return SHADOWTCB_FAILURE;
        }
     -  if (asprintf(&shadow, TCB_FMT, user_newname) == -1) {
    -+  shadow = asprintF_(TCB_FMT, user_newname);
    ++  shadow = aprintf(TCB_FMT, user_newname);
     +  if (shadow == NULL) {
                OUT_OF_MEMORY;
                return SHADOWTCB_FAILURE;
 4:  05f40737 =  4:  20364c16 lib/: Use vaprintf() instead of vasprintf(3)
 5:  910ca5cf =  5:  3f036027 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  840fd9d0 =  6:  c6c5b6f9 lib/, src/: Use xaprintf() instead of xasprintf()
 7:  ee37b595 =  7:  e91543af lib/, src/: Remove unnecessary variables
 8:  5510eb72 =  8:  36f2e2e3 lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  339e14ab =  9:  d46909ca lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling
v2b
  • Rebase
$ git range-diff 4.17.1..gh/asprintf_ master..asprintf_ 
 1:  cb92c9bf =  1:  194632cb lib/string/sprintf/: [v]aprintf(): Add functions
 2:  565dcd46 =  2:  4477dcd2 lib/tcbfuncs.c: Split conditionals
 3:  dc720127 =  3:  1ec6264e lib/, src/: Use aprintf() instead of asprintf(3)
 4:  20364c16 =  4:  75b15ee3 lib/: Use vaprintf() instead of vasprintf(3)
 5:  3f036027 =  5:  183e3e05 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
 6:  c6c5b6f9 =  6:  3817fcee lib/, src/: Use xaprintf() instead of xasprintf()
 7:  e91543af =  7:  0f4c4292 lib/, src/: Remove unnecessary variables
 8:  36f2e2e3 =  8:  9ee3c41b lib/tcbfuncs.c: shadowtcb_path_rel(): Use strdup(3) instead of its pattern
 9:  d46909ca =  9:  60287718 lib/tcbfuncs.c: shadowtcb_path_rel(): Centralize error handling

@alejandro-colomar alejandro-colomar changed the title [x][v]asprintf_(): Add APIs, and use them [x][v]asprintf_(): Add APIs, and use them instead of [x][v]asprintf(3) Jan 1, 2025
@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 7 times, most recently from 8426bbd to aaa727a Compare January 1, 2025 15:58
@alejandro-colomar alejandro-colomar marked this pull request as ready for review January 1, 2025 16:49
@alejandro-colomar alejandro-colomar changed the title [x][v]asprintf_(): Add APIs, and use them instead of [x][v]asprintf(3) [x][v]aprintf(): Add APIs, and use them instead of [x][v]asprintf(3) Jan 2, 2025
@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 2 times, most recently from d8ac495 to 75c5f3f Compare January 2, 2025 02:22
@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Jan 2, 2025

As a curiosity, this aprintf() API seems to be exactly the same that Plan9 calls smprint(3).

https://9fans.github.io/plan9port/man/man3/print.html

@alejandro-colomar alejandro-colomar force-pushed the asprintf_ branch 4 times, most recently from 339e14a to d46909c Compare January 6, 2025 02:27
These functions are just like [v]asprintf(3), but simpler.

They return the newly allocated memory, which allows us to use the
[[gnu::malloc(free)]] attribute, which enhances static analysis.
They also omit the length, which we don't care about at all.

As a curiosity, Plan9 seems to provide this same API, under the name
smprint(3).

Link: <https://9fans.github.io/plan9port/man/man3/print.html>
Signed-off-by: Alejandro Colomar <[email protected]>
This is in preparation for the next commit.

Signed-off-by: Alejandro Colomar <[email protected]>
…printf()

Wrap [v]aprintf() instead of [v]asprintf(3).

Repurpose x[v]asprintf()'s tests to test x[v]aprintf().

Signed-off-by: Alejandro Colomar <[email protected]>
This makes some temporary variables unnecessary.  They'll be removed in
the next commit.

Signed-off-by: Alejandro Colomar <[email protected]>
All these 3 branches have a compatible return value, which we can check
at once after the branches.

Signed-off-by: Alejandro Colomar <[email protected]>
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.

1 participant