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.
/// - priority: a priority value for the highlight group. For
/// example treesitter highlighting uses a value of 100.
/// - strict: boolean that indicates extmark should be placed
/// even if the line or column value is past the end of the
/// - strict: boolean that indicates extmark should not be placed
/// if the line or column value is past the end of the
/// buffer or end of the line respectively. Defaults to true.
///
/// @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;
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");
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) {
len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false));
}
if (col == -1) {
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");
goto error;
}
@ -627,9 +642,13 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
// reuse len from before
line2 = (int)line;
}
if (col2 > (Integer)len && strict) {
api_set_error(err, kErrorTypeValidation, "end_col value outside range");
goto error;
if (col2 > (Integer)len) {
if (strict) {
api_set_error(err, kErrorTypeValidation, "end_col value outside range");
goto error;
} else {
col2 = (int)len;
}
}
} else if (line2 >= 0) {
col2 = 0;