examples/sessioninfo: cast printf string mask length to int

Found via `-Wformat-signedness`:
```
docs/examples/sessioninfo.c: In function 'wrfu':
docs/examples/sessioninfo.c:75:53: error: field precision specifier '.*' expects argument of type 'int', but argument 4 has type 'unsigned int' [-Werror=format=]
  fprintf(stderr, "Certificate #%u: %.*s", i, dn.size, dn.data);
                                      ^
```
Ref: https://github.com/curl/curl/actions/runs/18320729052/job/52172864438?pr=18343#step:13:30
Ref: https://github.com/curl/curl/actions/runs/18320729095/job/52172886899?pr=18343#step:19:27

Also:
- drop unnecessary parenthesis.
- scope variables.

Ref: #18343
Closes #18918
This commit is contained in:
Viktor Szakats 2025-10-07 20:30:06 +02:00
parent 9f52458e7d
commit 1103ccb73e
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201

View file

@ -46,8 +46,6 @@ static CURL *curl;
static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
{
const struct curl_tlssessioninfo *info;
unsigned int cert_list_size;
const gnutls_datum_t *chainp;
CURLcode res;
(void)stream;
@ -56,11 +54,14 @@ static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
res = curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &info);
if(!res) {
unsigned int cert_list_size;
const gnutls_datum_t *chainp;
switch(info->backend) {
case CURLSSLBACKEND_GNUTLS:
/* info->internals is now the gnutls_session_t */
chainp = gnutls_certificate_get_peers(info->internals, &cert_list_size);
if((chainp) && (cert_list_size)) {
if(chainp && cert_list_size) {
unsigned int i;
for(i = 0; i < cert_list_size; i++) {
@ -72,7 +73,8 @@ static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
gnutls_x509_crt_import(cert, &chainp[i], GNUTLS_X509_FMT_DER)) {
if(GNUTLS_E_SUCCESS ==
gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_FULL, &dn)) {
fprintf(stderr, "Certificate #%u: %.*s", i, dn.size, dn.data);
fprintf(stderr, "Certificate #%u: %.*s", i,
(int)dn.size, dn.data);
gnutls_free(dn.data);
}