Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsigned/signed comparison warnings #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cli/gravity.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,12 @@ int main (int argc, const char* argv[]) {
if (type == OP_INLINE_RUN) {
char *buffer = mem_alloc(NULL, size+1024);
assert(buffer);
size = snprintf(buffer, size+1024, "func main() {%s};", input_file);
size =
#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
_snprintf_s(buffer, size+1024, sizeof buffer, "func main() {%s};", input_file);
#else
snprintf(buffer, size+1024, "func main() {%s};", input_file);
#endif
source_code = buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/gravity_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static gnode_t *parse_macro_statement (gravity_parser_t *parser);
// MARK: - Utils functions -

static gnode_t *get_enclosing (gravity_parser_t *parser, gnode_n tag) {
int32_t n = (int32_t)gnode_array_size(parser->declarations);
size_t n = gnode_array_size(parser->declarations);
if (!n) return NULL;

--n;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/gravity_semacheck2.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static gnode_t *lookup_identifier (gvisitor_t *self, const char *identifier, gno
bool base_is_class = ISA(base_node, NODE_CLASS_DECL);
bool base_is_static_function = (ISA(base_node, NODE_FUNCTION_DECL) && ((gnode_function_decl_t*)base_node)->storage == TOK_KEY_STATIC);

for (int i=(int)len-1; i>=0; --i) {
for (size_t i=len-1; i>=0; --i) {
gnode_t *target = gnode_array_get(decls, i);

// identify target type
Expand Down
6 changes: 3 additions & 3 deletions src/optionals/gravity_opt_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
static gravity_class_t *gravity_class_env = NULL;
static uint32_t refcount = 0;

static int argc = -1;
static size_t argc = -1;
static gravity_list_t *argv = NULL;

/**
Expand Down Expand Up @@ -143,10 +143,10 @@ void gravity_env_register(gravity_vm *vm) {
gravity_vm_setvalue(vm, GRAVITY_CLASS_ENV_NAME, VALUE_FROM_OBJECT(gravity_class_env));
}

void gravity_env_register_args(gravity_vm *vm, uint32_t _argc, const char **_argv) {
void gravity_env_register_args(gravity_vm *vm, size_t _argc, const char **_argv) {
argc = _argc;
argv = gravity_list_new(vm, argc);
for (int i = 0; i < _argc; ++i) {
for (size_t i = 0; i < _argc; ++i) {
gravity_value_t arg = VALUE_FROM_CSTRING(vm, _argv[i]);
marray_push(gravity_value_t, argv->array, arg);
}
Expand Down
2 changes: 1 addition & 1 deletion src/optionals/gravity_opt_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "gravity_value.h"

void gravity_env_register (gravity_vm *vm);
void gravity_env_register_args(gravity_vm *vm, uint32_t _argc, const char **_argv);
void gravity_env_register_args(gravity_vm *vm, size_t _argc, const char **_argv);
void gravity_env_free (void);
bool gravity_isenv_class (gravity_class_t *c);
const char *gravity_env_name (void);
Expand Down
2 changes: 1 addition & 1 deletion src/optionals/gravity_opt_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ static bool internal_file_iread (gravity_vm *vm, gravity_value_t *args, uint16_t
int c = fgetc(instance->file);
if ((c == -1) || feof(instance->file)) break;

*ptr++ = c;
*ptr++ = (char)c;
if (c == delimiter) break;

if (ptr + 2 >= eptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/optionals/gravity_opt_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static bool JSON_stringify (gravity_vm *vm, gravity_value_t *args, uint16_t narg

// special case for string because it can be huge (and must be quoted)
if (VALUE_ISA_STRING(value)) {
const int nchars = 5;
const size_t nchars = 5;
const char *v = VALUE_AS_STRING(value)->s;
size_t vlen = VALUE_AS_STRING(value)->len;

Expand Down
16 changes: 8 additions & 8 deletions src/runtime/gravity_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ static bool list_remove (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,
if (!VALUE_ISA_INT(GET_VALUE(1))) RETURN_ERROR("Parameter must be of type Int.");

gravity_int_t index = VALUE_AS_INT(GET_VALUE(1));
size_t count = marray_size(list->array);
gravity_int_t count = marray_size(list->array);
if ((index < 0) || (index >= count)) RETURN_ERROR("Out of bounds index.");

// remove an item means move others down
Expand Down Expand Up @@ -2447,11 +2447,11 @@ static bool string_count (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,
gravity_string_t *main_str = VALUE_AS_STRING(GET_VALUE(0));
gravity_string_t *str_to_count = VALUE_AS_STRING(GET_VALUE(1));

int j = 0;
int count = 0;
size_t j = 0;
size_t count = 0;

// iterate through whole string
for (int i = 0; i < main_str->len; ++i) {
for (size_t i = 0; i < main_str->len; ++i) {
if (main_str->s[i] == str_to_count->s[j]) {
// if the characters match and we are on the last character of the search
// string, then we have found a match
Expand Down Expand Up @@ -2516,7 +2516,7 @@ static bool string_upper (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,

// if no arguments passed, change the whole string to uppercase
if (nargs == 1) {
for (int i = 0; i <= main_str->len; ++i) {
for (size_t i = 0; i <= main_str->len; ++i) {
ret[i] = toupper(ret[i]);
}
}
Expand Down Expand Up @@ -2555,7 +2555,7 @@ static bool string_lower (gravity_vm *vm, gravity_value_t *args, uint16_t nargs,

// if no arguments passed, change the whole string to lowercase
if (nargs == 1) {
for (int i = 0; i <= main_str->len; ++i) {
for (size_t i = 0; i <= main_str->len; ++i) {
ret[i] = tolower(ret[i]);
}
}
Expand Down Expand Up @@ -2655,14 +2655,14 @@ static bool string_storeat (gravity_vm *vm, gravity_value_t *args, uint16_t narg
if (!VALUE_ISA_STRING(GET_VALUE(2))) RETURN_ERROR("A string needs to be assigned to a string index");

gravity_string_t *value = VALUE_AS_STRING(GET_VALUE(2));
register int32_t index = (int32_t)VALUE_AS_INT(idxvalue);
register size_t index = (int32_t)VALUE_AS_INT(idxvalue);

if (index < 0) index = string->len + index;
if (index < 0 || index >= string->len) RETURN_ERROR("Out of bounds error: index %d beyond bounds 0...%d", index, string->len-1);
if (index+value->len - 1 >= string->len) RETURN_ERROR("Out of bounds error: End of inserted string exceeds the length of the initial string");

// this code is not UTF-8 safe
for (int i = index; i < index+value->len; ++i) {
for (size_t i = index; i < index+value->len; ++i) {
string->s[i] = value->s[i-index];
}

Expand Down