Use bounded string copies when renumbering
Some checks failed
akbasic CI Build / akgl_build (push) Has been cancelled
akbasic CI Build / mutation_test (push) Has been cancelled
akbasic CI Build / coverage (push) Has been cancelled
akbasic CI Build / cmake_build (push) Has been cancelled
akbasic CI Build / sanitizers (push) Has been cancelled
Some checks failed
akbasic CI Build / akgl_build (push) Has been cancelled
akbasic CI Build / mutation_test (push) Has been cancelled
akbasic CI Build / coverage (push) Has been cancelled
akbasic CI Build / cmake_build (push) Has been cancelled
akbasic CI Build / sanitizers (push) Has been cancelled
This commit is contained in:
@@ -374,8 +374,10 @@ akerr_ErrorContext *akbasic_renumber(akbasic_Runtime *obj, int64_t newstart, int
|
||||
* of running it over source that arrived without any.
|
||||
*/
|
||||
obj->renumber_line.numbered = true;
|
||||
PASS(errctx, aksl_memcpy(&obj->source[i], &obj->renumber_line,
|
||||
sizeof(obj->source[i])));
|
||||
PASS(errctx, aksl_strncpy(obj->source[i].code, AKBASIC_MAX_LINE_LENGTH,
|
||||
obj->renumber_line.code, AKBASIC_MAX_LINE_LENGTH));
|
||||
obj->source[i].lineno = obj->renumber_line.lineno;
|
||||
obj->source[i].numbered = obj->renumber_line.numbered;
|
||||
}
|
||||
|
||||
/* Move the already-rewritten lines in place. The map is a partial
|
||||
@@ -389,34 +391,47 @@ akerr_ErrorContext *akbasic_renumber(akbasic_Runtime *obj, int64_t newstart, int
|
||||
if ( map[i] < 0 || obj->renumber_visited[i] ) {
|
||||
continue;
|
||||
}
|
||||
PASS(errctx, aksl_memcpy(&displaced, &obj->source[i], sizeof(displaced)));
|
||||
PASS(errctx, aksl_strncpy(displaced.code, AKBASIC_MAX_LINE_LENGTH,
|
||||
obj->source[i].code, AKBASIC_MAX_LINE_LENGTH));
|
||||
displaced.lineno = obj->source[i].lineno;
|
||||
displaced.numbered = obj->source[i].numbered;
|
||||
for ( ;; ) {
|
||||
int64_t destination = map[current];
|
||||
|
||||
obj->renumber_visited[current] = 1;
|
||||
if ( destination == i ) {
|
||||
displaced.lineno = destination;
|
||||
PASS(errctx, aksl_memcpy(&obj->source[destination], &displaced,
|
||||
sizeof(displaced)));
|
||||
PASS(errctx, aksl_strncpy(obj->source[destination].code, AKBASIC_MAX_LINE_LENGTH,
|
||||
displaced.code, AKBASIC_MAX_LINE_LENGTH));
|
||||
obj->source[destination].lineno = displaced.lineno;
|
||||
obj->source[destination].numbered = displaced.numbered;
|
||||
break;
|
||||
}
|
||||
if ( map[destination] < 0 ) {
|
||||
displaced.lineno = destination;
|
||||
PASS(errctx, aksl_memcpy(&obj->source[destination], &displaced,
|
||||
sizeof(displaced)));
|
||||
PASS(errctx, aksl_strncpy(obj->source[destination].code, AKBASIC_MAX_LINE_LENGTH,
|
||||
displaced.code, AKBASIC_MAX_LINE_LENGTH));
|
||||
obj->source[destination].lineno = displaced.lineno;
|
||||
obj->source[destination].numbered = displaced.numbered;
|
||||
PASS(errctx, aksl_memset(&obj->source[current], 0,
|
||||
sizeof(obj->source[current])));
|
||||
break;
|
||||
}
|
||||
PASS(errctx, aksl_memcpy(&next_line, &obj->source[destination],
|
||||
sizeof(displaced)));
|
||||
PASS(errctx, aksl_strncpy(next_line.code, AKBASIC_MAX_LINE_LENGTH,
|
||||
obj->source[destination].code, AKBASIC_MAX_LINE_LENGTH));
|
||||
next_line.lineno = obj->source[destination].lineno;
|
||||
next_line.numbered = obj->source[destination].numbered;
|
||||
displaced.lineno = destination;
|
||||
PASS(errctx, aksl_memcpy(&obj->source[destination], &displaced,
|
||||
sizeof(obj->renumber_line)));
|
||||
PASS(errctx, aksl_strncpy(obj->source[destination].code, AKBASIC_MAX_LINE_LENGTH,
|
||||
displaced.code, AKBASIC_MAX_LINE_LENGTH));
|
||||
obj->source[destination].lineno = displaced.lineno;
|
||||
obj->source[destination].numbered = displaced.numbered;
|
||||
PASS(errctx, aksl_memset(&obj->source[current], 0,
|
||||
sizeof(obj->source[current])));
|
||||
PASS(errctx, aksl_memcpy(&displaced, &next_line,
|
||||
sizeof(displaced)));
|
||||
PASS(errctx, aksl_strncpy(displaced.code, AKBASIC_MAX_LINE_LENGTH,
|
||||
next_line.code, AKBASIC_MAX_LINE_LENGTH));
|
||||
displaced.lineno = next_line.lineno;
|
||||
displaced.numbered = next_line.numbered;
|
||||
current = destination;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user