MCPcopy Create free account
hub / github.com/F-Stack/f-stack / __json_format_str

Function __json_format_str

dpdk/lib/telemetry/telemetry_json.h:133–159  ·  view source on GitHub ↗

* @internal * This function acts the same as __json_snprintf(buf, len, "%s%s%s", prefix, str, suffix) * except that it does proper escaping of "str" as necessary. Prefix and suffix should be compile- * time constants, or values not needing escaping. * Drops any invalid characters we don't support */

Source from the content-addressed store, hash-verified

131 * Drops any invalid characters we don't support
132 */
133static inline int
134__json_format_str(char *buf, const int len, const char *prefix, const char *str, const char *suffix)
135{
136 int ret;
137 char saved[4] = "";
138 char *tmp;
139
140 if (strnlen(buf, sizeof(saved)) < sizeof(saved)) {
141 /* we have only a few bytes in buffer, so save them off to restore on error*/
142 strcpy(saved, buf);
143 ret = __json_format_str_to_buf(buf, len, prefix, str, suffix);
144 if (ret == 0)
145 strcpy(buf, saved); /* restore */
146 return ret;
147 }
148
149 tmp = malloc(len);
150 if (tmp == NULL)
151 return 0;
152
153 ret = __json_format_str_to_buf(tmp, len, prefix, str, suffix);
154 if (ret > 0)
155 strcpy(buf, tmp);
156
157 free(tmp);
158 return ret;
159}
160
161/* Copies an empty array into the provided buffer. */
162static inline int

Callers 3

rte_tel_json_strFunction · 0.85
rte_tel_json_add_obj_strFunction · 0.85

Calls 4

strnlenFunction · 0.85
__json_format_str_to_bufFunction · 0.85
mallocFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected