basic: make check-pointer-deref clean
Add the needed assert changes to make the code clean for the new check-pointer-deref script. Note that for `_cmp()` functions its a bit of a question if we want `assert()` or `POINTER_MAY_BE_NULL()` here. The former is more correct but it adds a (small) runtime hit. If we use POINTER_MAY_BE_NULL() it is compiled out but strictly speaking it is wrong (so at least we would need a comment).
This commit is contained in:
@@ -174,6 +174,9 @@ char* ascii_strlower_n(char *s, size_t n) {
|
||||
|
||||
int ascii_strcasecmp_n(const char *a, const char *b, size_t n) {
|
||||
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
for (; n > 0; a++, b++, n--) {
|
||||
int x, y;
|
||||
|
||||
@@ -276,6 +279,10 @@ static bool string_has_ansi_sequence(const char *s, size_t len) {
|
||||
}
|
||||
|
||||
static size_t previous_ansi_sequence(const char *s, size_t length, const char **ret_where) {
|
||||
|
||||
assert(s);
|
||||
assert(ret_where);
|
||||
|
||||
/* Locate the previous ANSI sequence and save its start in *ret_where and return length. */
|
||||
|
||||
for (size_t i = length - 2; i > 0; i--) { /* -2 because at least two bytes are needed */
|
||||
@@ -1133,6 +1140,7 @@ int string_truncate_lines(const char *s, size_t n_lines, char **ret) {
|
||||
size_t n = 0;
|
||||
|
||||
assert(s);
|
||||
assert(ret);
|
||||
|
||||
/* Truncate after the specified number of lines. Returns > 0 if a truncation was applied or == 0 if
|
||||
* there were fewer lines in the string anyway. Trailing newlines on input are ignored, and not
|
||||
@@ -1187,6 +1195,8 @@ int string_extract_line(const char *s, size_t i, char **ret) {
|
||||
const char *p = s;
|
||||
size_t c = 0;
|
||||
|
||||
assert(ret);
|
||||
|
||||
/* Extract the i'nth line from the specified string. Returns > 0 if there are more lines after that,
|
||||
* and == 0 if we are looking at the last line or already beyond the last line. As special
|
||||
* optimization, if the first line is requested and the string only consists of one line we return
|
||||
|
||||
Reference in New Issue
Block a user