Skip to content

Commit

Permalink
Improve printf handling of size_t args
Browse files Browse the repository at this point in the history
The %*s format takes two arguments, a precision length/width and
an actual string; the length is specified as a signed integer.
The size_t length field of the gss_buffer_desc type is an unsigned
type, which must be cast or otherwise converted to a signed type
to match the format string expectations.
I do not think that the length will approach SIZE_T_MAX in practice,
due to buffer constraints, so do not include handling for the
edge case.

There is a '%zu' format string for printing size_ts, but it is not
available everywhere (e.g., AIX).  Instead, use the
unsigned long long abomination.
  • Loading branch information
kaduk committed Jul 2, 2012
1 parent 203de6e commit e4a3c43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/appl/gss-sample/gss-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ showLocalIdentity(OM_uint32 *minor, gss_name_t name)

major = gss_localname(minor, name, GSS_C_NO_OID, &localname);
if (major == GSS_S_COMPLETE)
printf("localname: %-*s\n", localname.length, localname.value);
printf("localname: %-*s\n", (int)localname.length, localname.value);
else if (major != GSS_S_UNAVAILABLE)
display_status("gss_localname", major, *minor);
gss_release_buffer(minor, &localname);
Expand Down
7 changes: 4 additions & 3 deletions src/lib/rpc/auth_gssapi_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void auth_gssapi_display_status_1(
putc ('\n', stderr);
if (misc_debug_gssapi)
gssrpcint_printf("GSS-API authentication error %s: %*s\n",
m, msg.length, (char *) msg.value);
m, (int)msg.length, (char *) msg.value);
(void) gss_release_buffer(&minor_stat, &msg);

if (!msg_ctx)
Expand Down Expand Up @@ -296,8 +296,9 @@ bool_t auth_gssapi_unwrap_data(
if (*major != GSS_S_COMPLETE)
return FALSE;

PRINTF(("gssapi_unwrap_data: %d bytes data, %d bytes sealed\n",
out_buf.length, in_buf.length));
PRINTF(("gssapi_unwrap_data: %llu bytes data, %llu bytes sealed\n",
(unsigned long long)out_buf.length,
(unsigned long long)in_buf.length));

xdrmem_create(&temp_xdrs, out_buf.value, out_buf.length, XDR_DECODE);

Expand Down

0 comments on commit e4a3c43

Please sign in to comment.