@@ -576,9 +576,9 @@
* like buf_null_terminate, but operate on strings
*/
void
-string_null_terminate(char *str, int len, int capacity)
+string_null_terminate(char *str, size_t len, size_t capacity)
{
- ASSERT(len >= 0 && len <= capacity && capacity > 0);
+ ASSERT(len <= capacity && capacity > 0);
if (len < capacity)
{
*(str + len) = '\0';
@@ -872,7 +872,7 @@
* @param capacity Total size of the character buffer in bytes.
*/
#ifdef _WIN32
-void string_null_terminate(char *str, int len, int capacity);
+void string_null_terminate(char *str, size_t len, size_t capacity);
#endif
/**@}*/
/* End of string utility functions */
@@ -53,7 +53,7 @@
void
-query_user_add(char *prompt, char *resp, int resp_len, bool echo)
+query_user_add(char *prompt, char *resp, size_t resp_len, bool echo)
{
int i;
@@ -32,10 +32,10 @@
*/
struct _query_user
{
- char *prompt; /**< Prompt to present to the user */
- char *response; /**< The user's response */
- int response_len; /**< Length the of the user response */
- bool echo; /**< True: The user should see what is being typed, otherwise mask it */
+ char *prompt; /**< Prompt to present to the user */
+ char *response; /**< The user's response */
+ size_t response_len; /**< Length the of the user response */
+ bool echo; /**< True: The user should see what is being typed, otherwise mask it */
};
#define QUERY_USER_NUMSLOTS 10
@@ -57,7 +57,7 @@
* @param echo Should the user input be echoed to the user? If False, input will be masked
*
*/
-void query_user_add(char *prompt, char *resp, int resp_len, bool echo);
+void query_user_add(char *prompt, char *resp, size_t resp_len, bool echo);
/**
@@ -115,7 +115,7 @@
*
*/
static inline bool
-query_user_SINGLE(char *prompt, char *resp, int resp_len, bool echo)
+query_user_SINGLE(char *prompt, char *resp, size_t resp_len, bool echo)
{
query_user_clear();
query_user_add(prompt, resp, resp_len, echo);
@@ -41,11 +41,6 @@
#include <termios.h>
#endif
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
#ifdef _WIN32
#include "win32.h"
@@ -62,11 +57,11 @@
* exit event is signaled.
*/
static bool
-get_console_input_win32(const char *prompt, const bool echo, char *input, const int capacity)
+get_console_input_win32(const char *prompt, const bool echo, char *input, const size_t capacity)
{
ASSERT(prompt);
ASSERT(input);
- ASSERT(capacity > 0);
+ ASSERT(capacity > 0 && capacity < INT_MAX);
input[0] = '\0';
@@ -110,16 +105,16 @@
return false;
}
- status = ReadConsoleW(in, winput, capacity, &len, NULL);
- WideCharToMultiByte(CP_UTF8, 0, winput, len, input, capacity, NULL, NULL);
+ status = ReadConsoleW(in, winput, (DWORD)capacity, &len, NULL);
+ WideCharToMultiByte(CP_UTF8, 0, winput, (int)len, input, (int)capacity, NULL, NULL);
free(winput);
}
else
{
- status = ReadFile(in, input, capacity, &len, NULL);
+ status = ReadFile(in, input, (DWORD)capacity, &len, NULL);
}
- string_null_terminate(input, (int)len, capacity);
+ string_null_terminate(input, len, capacity);
chomp(input);
if (!echo)
@@ -191,11 +186,11 @@
* @returns Returns True if user input was gathered
*/
static bool
-get_console_input(const char *prompt, const bool echo, char *input, const int capacity)
+get_console_input(const char *prompt, const bool echo, char *input, const size_t capacity)
{
ASSERT(prompt);
ASSERT(input);
- ASSERT(capacity > 0);
+ ASSERT(capacity > 0 && capacity <= INT_MAX);
input[0] = '\0';
#ifdef _WIN32
@@ -238,7 +233,7 @@
restore_tty = (tcsetattr(fileno(fp), TCSAFLUSH, &tty_tmp) == 0);
}
- if (fgets(input, capacity, fp) != NULL)
+ if (fgets(input, (int)capacity, fp) != NULL)
{
chomp(input);
ret = true;
@@ -294,7 +289,3 @@
return ret;
}
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
@@ -53,13 +53,8 @@
return (sd_booted() > 0) && (stat(SYSTEMD_ASK_PASSWORD_PATH, &c) == 0);
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
static bool
-get_console_input_systemd(const char *prompt, const bool echo, char *input, const int capacity)
+get_console_input_systemd(const char *prompt, const bool echo, char *input, const size_t capacity)
{
int std_out;
bool ret = false;
@@ -91,10 +86,6 @@
return ret;
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/**
* Systemd aware implementation of query_user_exec(). If systemd is not running
* it will fall back to use query_user_exec_builtin() instead.
@@ -47,11 +47,6 @@
}
#endif
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
bool
query_user_exec_builtin(void)
{
@@ -65,10 +60,6 @@
return mock();
}
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
void
management_auth_failure(const struct management *man, const char *type, const char *reason)
{