aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/input.c')
-rw-r--r--src/nvim/input.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/nvim/input.c b/src/nvim/input.c
index 96214d45c2..fb25968071 100644
--- a/src/nvim/input.c
+++ b/src/nvim/input.c
@@ -1,19 +1,17 @@
-// This is an open source non-commercial project. Dear PVS-Studio, please check
-// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
-
// input.c: high level functions for prompting the user or input
// like yes/no or number prompts.
+#include <limits.h>
#include <stdbool.h>
+#include <stdint.h>
#include <string.h>
-#include "nvim/ascii.h"
+#include "nvim/ascii_defs.h"
#include "nvim/event/multiqueue.h"
-#include "nvim/func_attr.h"
#include "nvim/getchar.h"
#include "nvim/gettext.h"
#include "nvim/globals.h"
-#include "nvim/highlight_defs.h"
+#include "nvim/highlight.h"
#include "nvim/input.h"
#include "nvim/keycodes.h"
#include "nvim/mbyte.h"
@@ -21,9 +19,8 @@
#include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/os/input.h"
-#include "nvim/types.h"
+#include "nvim/state_defs.h"
#include "nvim/ui.h"
-#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "input.c.generated.h" // IWYU pragma: export
@@ -56,7 +53,7 @@ int ask_yesno(const char *const str, const bool direct)
int r = ' ';
while (r != 'y' && r != 'n') {
// same highlighting as for wait_return()
- smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str);
+ smsg(HL_ATTR(HLF_R), "%s (y/n)?", str);
if (direct) {
r = get_keystroke(NULL);
} else {
@@ -86,21 +83,20 @@ int ask_yesno(const char *const str, const bool direct)
/// Translates the interrupt character for unix to ESC.
int get_keystroke(MultiQueue *events)
{
- char_u *buf = NULL;
+ uint8_t *buf = NULL;
int buflen = 150;
- int maxlen;
int len = 0;
int n;
int save_mapped_ctrl_c = mapped_ctrl_c;
mapped_ctrl_c = 0; // mappings are not used here
- for (;;) {
+ while (true) {
// flush output before waiting
ui_flush();
// Leave some room for check_termcode() to insert a key code into (max
// 5 chars plus NUL). And fix_input_buffer() can triple the number of
// bytes.
- maxlen = (buflen - 6 - len) / 3;
+ int maxlen = (buflen - 6 - len) / 3;
if (buf == NULL) {
buf = xmalloc((size_t)buflen);
} else if (maxlen < 10) {
@@ -113,7 +109,7 @@ int get_keystroke(MultiQueue *events)
// First time: blocking wait. Second time: wait up to 100ms for a
// terminal code to complete.
- n = os_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0, events);
+ n = os_inchar(buf + len, maxlen, len == 0 ? -1 : 100, 0, events);
if (n > 0) {
// Replace zero and K_SPECIAL by a special key code.
n = fix_input_buffer(buf + len, n);
@@ -166,7 +162,6 @@ int get_keystroke(MultiQueue *events)
int get_number(int colon, int *mouse_used)
{
int n = 0;
- int c;
int typed = 0;
if (mouse_used != NULL) {
@@ -181,10 +176,13 @@ int get_number(int colon, int *mouse_used)
no_mapping++;
allow_keys++; // no mapping here, but recognize keys
- for (;;) {
+ while (true) {
ui_cursor_goto(msg_row, msg_col);
- c = safe_vgetc();
+ int c = safe_vgetc();
if (ascii_isdigit(c)) {
+ if (n > INT_MAX / 10) {
+ return 0;
+ }
n = n * 10 + c - '0';
msg_putchar(c);
typed++;