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 numbers types #605

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/keymap-priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ XkbWrapGroupIntoRange(int32_t group,
* gives a negative result.
*/
if (group < 0)
return ((int) num_groups + (group % (int) num_groups));
return ((int32_t) num_groups + (group % (int32_t) num_groups));
else
return group % num_groups;
}
Expand Down
2 changes: 1 addition & 1 deletion src/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ xkb_keymap_unref(struct xkb_keymap *keymap)
if (key->groups) {
for (unsigned i = 0; i < key->num_groups; i++) {
if (key->groups[i].levels) {
for (unsigned j = 0; j < XkbKeyNumLevels(key, i); j++) {
for (xkb_level_index_t j = 0; j < XkbKeyNumLevels(key, i); j++) {
if (key->groups[i].levels[j].num_syms > 1)
free(key->groups[i].levels[j].s.syms);
if (key->groups[i].levels[j].num_actions > 1)
Expand Down
2 changes: 1 addition & 1 deletion src/keysym.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static bool
parse_keysym_hex(const char *s, uint32_t *out)
{
uint32_t result = 0;
int i;
unsigned int i;
for (i = 0; i < 8 && s[i] != '\0'; i++) {
result <<= 4;
if ('0' <= s[i] && s[i] <= '9')
Expand Down
3 changes: 1 addition & 2 deletions src/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ XKB_EXPORT bool
rxkb_context_include_path_append(struct rxkb_context *ctx, const char *path)
{
struct stat stat_buf;
int err;
char *tmp = NULL;
char rules[PATH_MAX];

Expand All @@ -535,7 +534,7 @@ rxkb_context_include_path_append(struct rxkb_context *ctx, const char *path)
return false;
}

err = stat(path, &stat_buf);
const int err = stat(path, &stat_buf);
if (err != 0)
return false;
if (!S_ISDIR(stat_buf.st_mode))
Expand Down
15 changes: 5 additions & 10 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,19 +1044,14 @@ XKB_EXPORT xkb_keysym_t
xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t kc)
{
const xkb_keysym_t *syms;
xkb_keysym_t sym;
int num_syms;

num_syms = xkb_state_key_get_syms(state, kc, &syms);
const int num_syms = xkb_state_key_get_syms(state, kc, &syms);
if (num_syms != 1)
return XKB_KEY_NoSymbol;

sym = syms[0];

if (should_do_caps_transformation(state, kc))
sym = xkb_keysym_to_upper(sym);

return sym;
const xkb_keysym_t sym = syms[0];
return should_do_caps_transformation(state, kc)
? xkb_keysym_to_upper(sym)
: sym;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

typedef struct {
const char *name;
unsigned int value;
uint32_t value;
} LookupEntry;

bool
Expand Down
62 changes: 30 additions & 32 deletions src/xkbcomp/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
const ExprDef *array_ndx, const ExprDef *value,
enum xkb_action_flags *flags_inout)
{
bool set;
bool set = false;

if (array_ndx)
return ReportActionNotArray(ctx, action, field);
Expand Down Expand Up @@ -266,7 +266,7 @@ CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
if (array_ndx)
return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);

unsigned int flags = 0;
uint32_t flags = 0;
if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE,
action, ACTION_FIELD_AFFECT,
Expand Down Expand Up @@ -312,7 +312,7 @@ CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action,
enum xkb_action_flags *flags_inout, int32_t *group_rtrn)
{
const ExprDef *spec;
xkb_layout_index_t idx;
xkb_layout_index_t idx = 0;
enum xkb_action_flags flags = *flags_inout;

if (array_ndx)
Expand Down Expand Up @@ -377,7 +377,7 @@ HandleMovePtr(struct xkb_context *ctx, const struct xkb_mod_set *mods,
struct xkb_pointer_action *act = &action->ptr;

if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
int val;
int64_t val = 0;
const bool absolute = (value->expr.op != EXPR_NEGATE &&
value->expr.op != EXPR_UNARY_PLUS);

Expand All @@ -390,10 +390,10 @@ HandleMovePtr(struct xkb_context *ctx, const struct xkb_mod_set *mods,

if (val < INT16_MIN || val > INT16_MAX) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"The %s field in the %s action must be in range %d..%d; "
"Action definition ignored\n",
"The %s field in the %s action must be in range %d..%d, "
"but got %"PRId64". Action definition ignored\n",
fieldText(field), ActionTypeText(action->type),
INT16_MIN, INT16_MAX);
INT16_MIN, INT16_MAX, val);
return false;
}

Expand Down Expand Up @@ -426,7 +426,7 @@ HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
struct xkb_pointer_button_action *act = &action->btn;

if (field == ACTION_FIELD_BUTTON) {
int btn;
int64_t btn = 0;

if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);
Expand All @@ -438,11 +438,11 @@ HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (btn < 0 || btn > 5) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"Button must specify default or be in the range 1..5; "
"Illegal button value %d ignored\n", btn);
"Illegal button value %"PRId64" ignored\n", btn);
return false;
}

act->button = btn;
act->button = (uint8_t) btn;
return true;
}
else if (action->type == ACTION_TYPE_PTR_LOCK &&
Expand All @@ -451,7 +451,7 @@ HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
&act->flags);
}
else if (field == ACTION_FIELD_COUNT) {
int val;
int64_t val = 0;

if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);
Expand All @@ -463,7 +463,7 @@ HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (val < 0 || val > 255) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"The count field must have a value in the range 0..255; "
"Illegal count %d ignored\n", val);
"Illegal count %"PRId64" ignored\n", val);
return false;
}

Expand All @@ -489,7 +489,7 @@ HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
struct xkb_pointer_default_action *act = &action->dflt;

if (field == ACTION_FIELD_AFFECT) {
unsigned int val;
uint32_t val = 0;

if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);
Expand All @@ -501,7 +501,7 @@ HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
}
else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
const ExprDef *button;
int btn;
int64_t btn = 0;

if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);
Expand All @@ -523,7 +523,7 @@ HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (btn < 0 || btn > 5) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"New default button value must be in the range 1..5; "
"Illegal default button value %d ignored\n", btn);
"Illegal default button value %"PRId64" ignored\n", btn);
return false;
}
if (btn == 0) {
Expand All @@ -533,7 +533,7 @@ HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
return false;
}

act->value = (int8_t)(value->expr.op == EXPR_NEGATE ? -btn: btn);
act->value = (int8_t) (value->expr.op == EXPR_NEGATE ? -btn: btn);
return true;
}

Expand All @@ -549,7 +549,7 @@ HandleSwitchScreen(struct xkb_context *ctx, const struct xkb_mod_set *mods,

if (field == ACTION_FIELD_SCREEN) {
const ExprDef *scrn;
int val;
int64_t val = 0;

if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);
Expand All @@ -572,7 +572,7 @@ HandleSwitchScreen(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (val < INT8_MIN || val > INT8_MAX) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"Screen index must be in the range %d..%d; "
"Illegal screen value %d ignored\n",
"Illegal screen value %"PRId64" ignored\n",
INT8_MIN, INT8_MAX, val);
return false;
}
Expand Down Expand Up @@ -600,7 +600,7 @@ HandleSetLockControls(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);

unsigned int mask = 0;
uint32_t mask = 0;
if (!ExprResolveMask(ctx, value, &mask, ctrlMaskNames))
return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
field, "controls mask");
Expand All @@ -624,7 +624,7 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
struct xkb_private_action *act = &action->priv;

if (field == ACTION_FIELD_TYPE) {
int type;
int64_t type = 0;

if (array_ndx)
return ReportActionNotArray(ctx, action->type, field);
Expand All @@ -636,7 +636,7 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (type < 0 || type > 255) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"Private action type must be in the range 0..255; "
"Illegal type %d ignored\n", type);
"Illegal type %"PRId64" ignored\n", type);
return false;
}

Expand All @@ -653,7 +653,7 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (type < ACTION_TYPE_PRIVATE) {
log_info(ctx, XKB_LOG_MESSAGE_NO_ID,
"Private actions of type %s are not supported; Ignored\n",
ActionTypeText(type));
ActionTypeText((enum xkb_action_type) type));
act->type = ACTION_TYPE_NONE;
}
else {
Expand All @@ -664,16 +664,14 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
}
else if (field == ACTION_FIELD_DATA) {
if (array_ndx == NULL) {
xkb_atom_t val;
const char *str;
size_t len;
xkb_atom_t val = XKB_ATOM_NONE;

if (!ExprResolveString(ctx, value, &val))
return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE,
action->type, field, "string");

str = xkb_atom_text(ctx, val);
len = strlen(str);
const char *str = xkb_atom_text(ctx, val);
size_t len = strlen(str);
if (len < 1 || len > sizeof(act->data)) {
log_warn(ctx, XKB_LOG_MESSAGE_NO_ID,
"A private action has %ld data bytes; "
Expand All @@ -687,7 +685,7 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
return true;
}
else {
int ndx, datum;
int64_t ndx = 0, datum = 0;

if (!ExprResolveInteger(ctx, array_ndx, &ndx)) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
Expand All @@ -698,9 +696,9 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,

if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"The data for a private action is %lu bytes long; "
"Attempt to use data[%d] ignored\n",
(unsigned long) sizeof(act->data), ndx);
"The data for a private action is %zu bytes long; "
"Attempt to use data[%"PRId64"] ignored\n",
sizeof(act->data), ndx);
return false;
}

Expand All @@ -711,7 +709,7 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
if (datum < 0 || datum > 255) {
log_err(ctx, XKB_LOG_MESSAGE_NO_ID,
"All data for a private action must be 0..255; "
"Illegal datum %d ignored\n", datum);
"Illegal datum %"PRId64" ignored\n", datum);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/xkbcomp/ast-build.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ExprCreateString(xkb_atom_t str)
}

ExprDef *
ExprCreateInteger(int ival)
ExprCreateInteger(int64_t ival)
{
ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_INT, sizeof(ExprInteger));
if (!expr)
Expand Down
2 changes: 1 addition & 1 deletion src/xkbcomp/ast-build.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ExprDef *
ExprCreateString(xkb_atom_t str);

ExprDef *
ExprCreateInteger(int ival);
ExprCreateInteger(int64_t ival);

ExprDef *
ExprCreateFloat(void);
Expand Down
2 changes: 1 addition & 1 deletion src/xkbcomp/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ typedef struct {

typedef struct {
ExprCommon expr;
int ival;
int64_t ival;
} ExprInteger;

typedef struct {
Expand Down
Loading
Loading