| 1282 | } |
| 1283 | |
| 1284 | static char *agent_splice(const char *document, size_t length, size_t start, size_t end, |
| 1285 | const char *replacement) { |
| 1286 | size_t replacement_len = strlen(replacement); |
| 1287 | if (start > end || end > length || replacement_len > SIZE_MAX - (length - (end - start)) - 1U) { |
| 1288 | return NULL; |
| 1289 | } |
| 1290 | size_t new_length = length - (end - start) + replacement_len; |
| 1291 | char *updated = (char *)malloc(new_length + 1U); |
| 1292 | if (!updated) { |
| 1293 | return NULL; |
| 1294 | } |
| 1295 | memcpy(updated, document, start); |
| 1296 | memcpy(updated + start, replacement, replacement_len); |
| 1297 | memcpy(updated + start + replacement_len, document + end, length - end); |
| 1298 | updated[new_length] = '\0'; |
| 1299 | return updated; |
| 1300 | } |
| 1301 | |
| 1302 | static int agent_continue_edit(const char *config_path, const char *binary_path, bool remove) { |
| 1303 | char *document = NULL; |
no outgoing calls
no test coverage detected