Merge pull request #179 from ctiller/kill-printf

Remove uses of sprintf
pull/187/head^2
jboeuf 10 years ago
commit 10f4620e93
  1. 2
      src/core/channel/call_op_string.c
  2. 2
      src/core/channel/channel_args.c
  3. 2
      src/core/channel/client_channel.c
  4. 2
      src/core/channel/connected_channel.c
  5. 2
      src/core/httpcli/httpcli.c
  6. 2
      src/core/httpcli/httpcli_security_context.c
  7. 2
      src/core/iomgr/resolve_address_posix.c
  8. 2
      src/core/iomgr/sockaddr_utils.c
  9. 2
      src/core/iomgr/socket_utils_common_posix.c
  10. 2
      src/core/iomgr/tcp_posix.c
  11. 2
      src/core/security/credentials.c
  12. 2
      src/core/security/json_token.c
  13. 2
      src/core/security/secure_endpoint.c
  14. 2
      src/core/security/security_context.c
  15. 2
      src/core/statistics/census_rpc_stats.c
  16. 2
      src/core/statistics/census_tracing.c
  17. 2
      src/core/support/cmdline.c
  18. 2
      src/core/support/host_port.c
  19. 32
      src/core/support/string.c
  20. 11
      src/core/support/string.h
  21. 2
      src/core/surface/call.c
  22. 2
      src/core/surface/channel_create.c
  23. 2
      src/core/surface/client.c
  24. 2
      src/core/surface/completion_queue.c
  25. 2
      src/core/surface/event_string.c
  26. 2
      src/core/surface/lame_client.c
  27. 2
      src/core/surface/secure_channel_create.c
  28. 2
      src/core/surface/server.c
  29. 2
      src/core/transport/chttp2/frame_data.c
  30. 2
      src/core/transport/chttp2/hpack_parser.c
  31. 38
      src/core/transport/chttp2/timeout_encoding.c
  32. 3
      src/core/transport/chttp2/timeout_encoding.h
  33. 2
      src/core/transport/chttp2_transport.c
  34. 2
      test/core/echo/echo_test.c
  35. 2
      test/core/echo/server.c
  36. 2
      test/core/end2end/cq_verifier.c
  37. 2
      test/core/fling/fling_stream_test.c
  38. 2
      test/core/fling/fling_test.c
  39. 2
      test/core/security/credentials_test.c
  40. 2
      test/core/support/string_test.c
  41. 2
      test/core/transport/chttp2/bin_encoder_test.c
  42. 2
      test/core/transport/chttp2/stream_encoder_test.c
  43. 2
      test/core/transport/chttp2/timeout_encoding_test.c
  44. 2
      test/core/transport/transport_end2end_tests.c

@ -37,8 +37,8 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
#define MAX_APPEND 1024

@ -33,9 +33,9 @@
#include <grpc/grpc.h>
#include "src/core/channel/channel_args.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/string.h>
#include <string.h>

@ -40,9 +40,9 @@
#include "src/core/channel/connected_channel.h"
#include "src/core/channel/metadata_buffer.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>

@ -37,12 +37,12 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include "src/core/transport/transport.h"
#include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string.h>
#define MAX_BUFFER_LENGTH 8192
/* the protobuf library will (by default) start warning at 100megs */

@ -44,9 +44,9 @@
#include "src/core/security/security_context.h"
#include "src/core/security/google_root_certs.h"
#include "src/core/security/secure_transport_setup.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef struct {
gpr_slice request_text;

@ -36,9 +36,9 @@
#include <string.h>
#include "src/core/security/secure_transport_setup.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include "src/core/tsi/ssl_transport_security.h"
typedef struct {

@ -44,9 +44,9 @@
#include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/iomgr/socket_utils_posix.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>

@ -37,8 +37,8 @@
#include <errno.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/host_port.h>
#include <grpc/support/string.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>

@ -50,8 +50,8 @@
#include <errno.h>
#include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/support/string.h"
#include <grpc/support/host_port.h>
#include <grpc/support/string.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/sync.h>

@ -44,10 +44,10 @@
#include <sys/socket.h>
#include <unistd.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

@ -36,9 +36,9 @@
#include "src/core/httpcli/httpcli.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/security/json_token.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

@ -37,9 +37,9 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include "src/core/security/base64.h"
#include "src/core/support/string.h"
#include <openssl/bio.h>
#include <openssl/evp.h>

@ -32,11 +32,11 @@
*/
#include "src/core/security/secure_endpoint.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/slice.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include "src/core/tsi/transport_security_interface.h"

@ -39,12 +39,12 @@
#include "src/core/channel/http_client_filter.h"
#include "src/core/security/credentials.h"
#include "src/core/security/secure_endpoint.h"
#include "src/core/support/string.h"
#include "src/core/surface/lame_client.h"
#include "src/core/transport/chttp2/alpn.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string.h>
#include "src/core/tsi/fake_transport_security.h"
#include "src/core/tsi/ssl_transport_security.h"

@ -39,9 +39,9 @@
#include "src/core/statistics/census_tracing.h"
#include "src/core/statistics/window_stats.h"
#include "src/core/support/murmur_hash.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#define NUM_INTERVALS 3

@ -38,10 +38,10 @@
#include "src/core/statistics/census_rpc_stats.h"
#include "src/core/statistics/hash_table.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

@ -37,9 +37,9 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype;

@ -35,8 +35,8 @@
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/log.h>
#include <grpc/support/string.h>
int gpr_join_host_port(char **out, const char *host, int port) {
if (host[0] != '[' && strchr(host, ':') != NULL) {

@ -31,7 +31,7 @@
*
*/
#include <grpc/support/string.h>
#include "src/core/support/string.h"
#include <ctype.h>
#include <stddef.h>
@ -122,3 +122,33 @@ int gpr_parse_bytes_to_uint32(const char *buf, size_t len, gpr_uint32 *result) {
*result = out;
return 1;
}
void gpr_reverse_bytes(char *str, int len) {
char *p1, *p2;
for (p1 = str, p2 = str + len - 1; p2 > p1; ++p1, --p2) {
char temp = *p1;
*p1 = *p2;
*p2 = temp;
}
}
int gpr_ltoa(long value, char *string) {
int i = 0;
int neg = value < 0;
if (value == 0) {
string[0] = '0';
string[1] = 0;
return 1;
}
if (neg) value = -value;
while (value) {
string[i++] = '0' + value % 10;
value /= 10;
}
if (neg) string[i++] = '-';
gpr_reverse_bytes(string, i);
string[i] = 0;
return i;
}

@ -60,6 +60,17 @@ char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags);
int gpr_parse_bytes_to_uint32(const char *data, size_t length,
gpr_uint32 *result);
/* Minimum buffer size for calling ltoa */
#define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long))
/* Convert a long to a string in base 10; returns the length of the
output string (or 0 on failure).
output must be at least GPR_LTOA_MIN_BUFSIZE bytes long. */
int gpr_ltoa(long value, char *output);
/* Reverse a run of bytes */
void gpr_reverse_bytes(char *str, int len);
/* printf to a newly-allocated string. The set of supported formats may vary
between platforms.

@ -35,11 +35,11 @@
#include "src/core/channel/channel_stack.h"
#include "src/core/channel/metadata_buffer.h"
#include "src/core/iomgr/alarm.h"
#include "src/core/support/string.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/completion_queue.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <stdio.h>
#include <stdlib.h>

@ -48,10 +48,10 @@
#include "src/core/iomgr/tcp_client.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/client.h"
#include "src/core/support/string.h"
#include "src/core/transport/chttp2_transport.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>

@ -34,9 +34,9 @@
#include "src/core/surface/client.h"
#include "src/core/surface/call.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef struct { void *unused; } call_data;

@ -37,13 +37,13 @@
#include <string.h>
#include "src/core/iomgr/pollset.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
#include "src/core/surface/event_string.h"
#include "src/core/surface/surface_trace.h"
#include <grpc/support/alloc.h>
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#define NUM_TAG_BUCKETS 31

@ -35,7 +35,7 @@
#include <stdio.h>
#include <grpc/support/string.h>
#include "src/core/support/string.h"
#include <grpc/byte_buffer.h>
static size_t addhdr(char *p, grpc_event *ev) {

@ -36,11 +36,11 @@
#include <string.h>
#include "src/core/channel/channel_stack.h"
#include "src/core/support/string.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/call.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef struct { void *unused; } call_data;

@ -48,13 +48,13 @@
#include "src/core/security/auth.h"
#include "src/core/security/security_context.h"
#include "src/core/security/secure_transport_setup.h"
#include "src/core/support/string.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/client.h"
#include "src/core/transport/chttp2_transport.h"
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security_interface.h"

@ -40,12 +40,12 @@
#include "src/core/channel/channel_args.h"
#include "src/core/channel/connected_channel.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/completion_queue.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
typedef enum { PENDING_START, ALL_CALLS, CALL_LIST_COUNT } call_list;

@ -35,9 +35,9 @@
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
#include "src/core/transport/transport.h"

@ -38,10 +38,10 @@
#include <assert.h>
#include "src/core/transport/chttp2/bin_encoder.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
typedef enum {

@ -36,6 +36,8 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
static int round_up(int x, int divisor) {
return (x / divisor + (x % divisor != 0)) * divisor;
}
@ -53,15 +55,21 @@ static int round_up_to_three_sig_figs(int x) {
}
/* encode our minimum viable timeout value */
static void enc_tiny(char *buffer) { strcpy(buffer, "1n"); }
static void enc_tiny(char *buffer) { memcpy(buffer, "1n", 3); }
static void enc_ext(char *buffer, long value, char ext) {
int n = gpr_ltoa(value, buffer);
buffer[n] = ext;
buffer[n+1] = 0;
}
static void enc_seconds(char *buffer, long sec) {
if (sec % 3600 == 0) {
sprintf(buffer, "%ldH", sec / 3600);
enc_ext(buffer, sec / 3600, 'H');
} else if (sec % 60 == 0) {
sprintf(buffer, "%ldM", sec / 60);
enc_ext(buffer, sec / 60, 'M');
} else {
sprintf(buffer, "%ldS", sec);
enc_ext(buffer, sec, 'S');
}
}
@ -69,23 +77,23 @@ static void enc_nanos(char *buffer, int x) {
x = round_up_to_three_sig_figs(x);
if (x < 100000) {
if (x % 1000 == 0) {
sprintf(buffer, "%du", x / 1000);
enc_ext(buffer, x / 1000, 'u');
} else {
sprintf(buffer, "%dn", x);
enc_ext(buffer, x, 'n');
}
} else if (x < 100000000) {
if (x % 1000000 == 0) {
sprintf(buffer, "%dm", x / 1000000);
enc_ext(buffer, x / 1000000, 'm');
} else {
sprintf(buffer, "%du", x / 1000);
enc_ext(buffer, x / 1000, 'u');
}
} else if (x < 1000000000) {
sprintf(buffer, "%dm", x / 1000000);
enc_ext(buffer, x / 1000000, 'm');
} else {
/* note that this is only ever called with times of less than one second,
so if we reach here the time must have been rounded up to a whole second
(and no more) */
strcpy(buffer, "1S");
memcpy(buffer, "1S", 3);
}
}
@ -93,18 +101,18 @@ static void enc_micros(char *buffer, int x) {
x = round_up_to_three_sig_figs(x);
if (x < 100000) {
if (x % 1000 == 0) {
sprintf(buffer, "%dm", x / 1000);
enc_ext(buffer, x / 1000, 'm');
} else {
sprintf(buffer, "%du", x);
enc_ext(buffer, x, 'u');
}
} else if (x < 100000000) {
if (x % 1000000 == 0) {
sprintf(buffer, "%dS", x / 1000000);
enc_ext(buffer, x / 1000000, 'S');
} else {
sprintf(buffer, "%dm", x / 1000);
enc_ext(buffer, x / 1000, 'm');
}
} else {
sprintf(buffer, "%dS", x / 1000000);
enc_ext(buffer, x / 1000000, 'S');
}
}

@ -34,8 +34,11 @@
#ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H_
#define __GRPC_INTERNAL_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H_
#include "src/core/support/string.h"
#include <grpc/support/time.h>
#define GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1)
/* Encode/decode timeouts to the GRPC over HTTP2 format;
encoding may round up arbitrarily */
void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer);

@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include "src/core/transport/chttp2/frame_data.h"
#include "src/core/transport/chttp2/frame_goaway.h"
#include "src/core/transport/chttp2/frame_ping.h"
@ -53,7 +54,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
#define DEFAULT_WINDOW 65535

@ -42,10 +42,10 @@
#include <sys/wait.h>
#include "src/core/iomgr/socket_utils_posix.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include "test/core/util/port.h"
int test_client(const char *root, const char *host, int port) {

@ -39,11 +39,11 @@
#include <string.h>
#include <time.h>
#include "src/core/support/string.h"
#include "test/core/util/test_config.h"
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/time.h>
#include "test/core/util/port.h"

@ -45,10 +45,10 @@
#include <string.h>
#include "src/core/surface/event_string.h"
#include "src/core/support/string.h"
#include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/time.h>
#include <grpc/support/useful.h>

@ -41,9 +41,9 @@
#include <sys/types.h>
#include <sys/wait.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/string.h>
#include "test/core/util/port.h"
int main(int argc, char **argv) {

@ -43,7 +43,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/string.h>
#include "src/core/support/string.h"
#include "test/core/util/port.h"
int main(int argc, char **argv) {

@ -37,9 +37,9 @@
#include "src/core/httpcli/httpcli.h"
#include "src/core/security/json_token.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/time.h>
#include "test/core/util/test_config.h"
#include <openssl/rsa.h>

@ -31,7 +31,7 @@
*
*/
#include <grpc/support/string.h>
#include "src/core/support/string.h"
#include <stddef.h>
#include <stdlib.h>

@ -35,9 +35,9 @@
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
static int all_ok = 1;

@ -35,10 +35,10 @@
#include <stdio.h>
#include "src/core/support/string.h"
#include "src/core/transport/chttp2/hpack_parser.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include "test/core/util/parse_hexstring.h"
#include "test/core/util/slice_splitter.h"
#include "test/core/util/test_config.h"

@ -43,7 +43,7 @@
#define LOG_TEST() gpr_log(GPR_INFO, "%s", __FUNCTION__)
static void assert_encodes_as(gpr_timespec ts, const char *s) {
char buffer[32];
char buffer[GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
grpc_chttp2_encode_timeout(ts, buffer);
gpr_log(GPR_INFO, "check '%s' == '%s'", buffer, s);
GPR_ASSERT(0 == strcmp(buffer, s));

@ -37,10 +37,10 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include "src/core/transport/transport.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>

Loading…
Cancel
Save