Address 'review'

This commit is contained in:
Michael Lingelbach
2022-01-12 12:01:29 -08:00
parent 11142f6ffe
commit d0d4fb792f

View File

@@ -404,8 +404,8 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// for left). Defaults to false. /// for left). Defaults to false.
/// - priority: a priority value for the highlight group. For /// - priority: a priority value for the highlight group. For
/// example treesitter highlighting uses a value of 100. /// example treesitter highlighting uses a value of 100.
/// - strict: boolean that indicates extmark should be placed /// - strict: boolean that indicates extmark should not be placed
/// even if the line or column value is past the end of the /// if the line or column value is past the end of the
/// buffer or end of the line respectively. Defaults to true. /// buffer or end of the line respectively. Defaults to true.
/// ///
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
@@ -603,16 +603,31 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
bool strict = true; bool strict = true;
OPTION_TO_BOOL(strict, strict, true); OPTION_TO_BOOL(strict, strict, true);
if (line < 0 || (line > buf->b_ml.ml_line_count && strict)) { if (line < 0 ) {
api_set_error(err, kErrorTypeValidation, "line value outside range"); api_set_error(err, kErrorTypeValidation, "line value outside range");
goto error; goto error;
}
else if (line > buf->b_ml.ml_line_count) {
if (strict) {
api_set_error(err, kErrorTypeValidation, "line value outside range");
goto error;
} else {
line = buf->b_ml.ml_line_count;
}
} else if (line < buf->b_ml.ml_line_count) { } else if (line < buf->b_ml.ml_line_count) {
len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false)); len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false));
} }
if (col == -1) { if (col == -1) {
col = (Integer)len; col = (Integer)len;
} else if (col < -1 || (col > (Integer)len && strict)) { } else if (col > (Integer)len) {
if (strict) {
api_set_error(err, kErrorTypeValidation, "col value outside range");
goto error;
} else {
col = (Integer)len;
}
} else if (col < -1 ) {
api_set_error(err, kErrorTypeValidation, "col value outside range"); api_set_error(err, kErrorTypeValidation, "col value outside range");
goto error; goto error;
} }
@@ -627,9 +642,13 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
// reuse len from before // reuse len from before
line2 = (int)line; line2 = (int)line;
} }
if (col2 > (Integer)len && strict) { if (col2 > (Integer)len) {
api_set_error(err, kErrorTypeValidation, "end_col value outside range"); if (strict) {
goto error; api_set_error(err, kErrorTypeValidation, "end_col value outside range");
goto error;
} else {
col2 = (int)len;
}
} }
} else if (line2 >= 0) { } else if (line2 >= 0) {
col2 = 0; col2 = 0;