-
Notifications
You must be signed in to change notification settings - Fork 35
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 warnings on 32-bit platforms #159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,8 +157,8 @@ static struct wl_buffer* create_buffer(void) | |
|
||
// generate unique file name | ||
clock_gettime(CLOCK_MONOTONIC, &ts); | ||
snprintf(path, sizeof(path), "/" APP_NAME "_%lx", | ||
(ts.tv_sec << 32) | ts.tv_nsec); | ||
snprintf(path, sizeof(path), "/" APP_NAME "_%" PRIx64, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to use one style for printf. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I don't know what you mean by this. |
||
((uint64_t)ts.tv_sec << 32) | ts.tv_nsec); | ||
|
||
// open shared mem | ||
fd = shm_open(path, O_RDWR | O_CREAT | O_EXCL, 0600); | ||
|
@@ -698,8 +698,8 @@ void ui_create(void) | |
// create unique application id | ||
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { | ||
char app_id[64]; | ||
const uint64_t timestamp = (ts.tv_sec << 32) | ts.tv_nsec; | ||
snprintf(app_id, sizeof(app_id), APP_NAME "_%lx", timestamp); | ||
const uint64_t timestamp = ((uint64_t)ts.tv_sec << 32) | ts.tv_nsec; | ||
snprintf(app_id, sizeof(app_id), APP_NAME "_%" PRIx64, timestamp); | ||
str_dup(app_id, &ctx.app_id); | ||
} else { | ||
str_dup(APP_NAME, &ctx.app_id); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
#include "pixmap.h" | ||
|
||
#include <limits.h> | ||
|
||
// Configuration parameters | ||
#define UI_CFG_APP_ID "app_id" | ||
#define UI_CFG_FULLSCREEN "fullscreen" | ||
|
@@ -15,7 +17,7 @@ | |
// Special ids for windows size and position | ||
#define SIZE_FROM_IMAGE 0 | ||
#define SIZE_FROM_PARENT 1 | ||
#define POS_FROM_PARENT 0xffffffff | ||
#define POS_FROM_PARENT SSIZE_MAX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a reason to change this. What the purpose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/** | ||
* Create User Interface context. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need these type casts?
0xffffffff
fits uint32_t. Also color is always 32 bits.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 32-bit systems,
0xffffffff
will be considered a 4-byteunsigned int
by compilers, as it can't fit in anint
without overflowing. Also,ssize_t num
will be a 4-byteint
(not guaranteed by the C spec, but what compilers usually do). The compiler will emit a warning because these two different types are being compared, and the compiler doesn't know whether it should generate a signed or unsigned comparison. The cast touint64_t
assures that these two values can be safely compared on both 32-bit and 64-bit systems. On 64-bit systems, because this code checks for the validity of a color,num
can be greater than 32-bits (it's inputted by the user in the configuration file). A cast ofnum
touint32_t
wouldn't suffice, as values higher than0xffffffff
would be accepted as valid colors, as they'd be truncated before the comparison.