MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / forwarding_cb

Function forwarding_cb

deps/jemalloc/test/unit/emitter.c:24–65  ·  view source on GitHub ↗

* Forwards all writes to the passed-in buf_v (which should be cast from a * buf_descriptor_t *). */

Source from the content-addressed store, hash-verified

22 * buf_descriptor_t *).
23 */
24static void
25forwarding_cb(void *buf_descriptor_v, const char *str) {
26 buf_descriptor_t *buf_descriptor = (buf_descriptor_t *)buf_descriptor_v;
27
28 if (print_raw) {
29 malloc_printf("%s", str);
30 }
31 if (print_escaped) {
32 const char *it = str;
33 while (*it != '\0') {
34 if (!buf_descriptor->mid_quote) {
35 malloc_printf("\"");
36 buf_descriptor->mid_quote = true;
37 }
38 switch (*it) {
39 case '\\':
40 malloc_printf("\\");
41 break;
42 case '\"':
43 malloc_printf("\\\"");
44 break;
45 case '\t':
46 malloc_printf("\\t");
47 break;
48 case '\n':
49 malloc_printf("\\n\"\n");
50 buf_descriptor->mid_quote = false;
51 break;
52 default:
53 malloc_printf("%c", *it);
54 }
55 it++;
56 }
57 }
58
59 size_t written = malloc_snprintf(buf_descriptor->buf,
60 buf_descriptor->len, "%s", str);
61 assert_zu_eq(written, strlen(str), "Buffer overflow!");
62 buf_descriptor->buf += written;
63 buf_descriptor->len -= written;
64 assert_zu_gt(buf_descriptor->len, 0, "Buffer out of space!");
65}
66
67static void
68assert_emit_output(void (*emit_fn)(emitter_t *),

Callers

nothing calls this directly

Calls 1

malloc_printfFunction · 0.50

Tested by

no test coverage detected