summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2023-02-07 15:17:08 -0600
committerthe lemons <citrons@mondecitronne.com>2023-02-07 15:17:08 -0600
commit4300520103c7196764561cdf7d34734495d708c0 (patch)
tree3e440f7258627565bfefd17a6bbf9cc1d62161ca
parent285025ee086b7631cb102c20300c8da7f2d9a52e (diff)
signedness problems
-rw-r--r--memview.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/memview.c b/memview.c
index 4491f05..7f7dbd4 100644
--- a/memview.c
+++ b/memview.c
@@ -18,39 +18,39 @@ struct viewer {
#define BIT_OF(X, I) (((X) >> (I)) & 1ULL)
-static uintptr_t zorder(int x, int y) {
+static uintptr_t zorder(unsigned int x, unsigned int y) {
uintptr_t z = 0;
- unsigned int ux, uy;
- memcpy(&ux, &x, sizeof(unsigned int));
- memcpy(&uy, &y, sizeof(unsigned int));
// interleaving bits results in a point on the z-order curve
for (int i = 0; i < sizeof(x) * CHAR_BIT; i++)
- z |= (BIT_OF(ux, i) << i*2) | (BIT_OF(uy, i) << (i*2 + 1));
+ z |= (BIT_OF(x, i) << i*2) | (BIT_OF(y, i) << (i*2 + 1));
return z;
}
-static void unzorder(uintptr_t z, int *x, int *y) {
- unsigned int ux, uy = 0;
+static void unzorder(uintptr_t z, unsigned int *x, unsigned int *y) {
+ *x = 0; *y = 0;
for (int i = 0; i < sizeof(z) * CHAR_BIT / 2; i++) {
- ux |= BIT_OF(z, i*2) << i;
- uy |= BIT_OF(z, i*2 + 1) << i;
+ *x |= BIT_OF(z, i*2) << i;
+ *y |= BIT_OF(z, i*2 + 1) << i;
}
- memcpy(x, &ux, sizeof(int));
- memcpy(y, &uy, sizeof(int));
}
uintptr_t to_addr(int x, int y) {
- uintptr_t page = zorder(x / PAGE_WIDTH, y / PAGE_HEIGHT);
+ unsigned int ux, uy;
+ memcpy(&ux, &x, sizeof(unsigned int));
+ memcpy(&uy, &y, sizeof(unsigned int));
+ uintptr_t page = zorder(ux / PAGE_WIDTH, uy / PAGE_HEIGHT);
int offset = x % PAGE_WIDTH + y % PAGE_HEIGHT * PAGE_WIDTH;
return page * PAGE_SIZE + offset;
}
void to_pos(uintptr_t addr, int *x, int *y) {
- int px, py;
+ unsigned int px, py;
unzorder(addr / PAGE_SIZE, &px, &py);
int offset = addr % PAGE_SIZE;
- *x = px * PAGE_WIDTH + offset % PAGE_WIDTH;
- *y = py * PAGE_HEIGHT + offset / PAGE_WIDTH;
+ unsigned int ux = px * PAGE_WIDTH + offset % PAGE_WIDTH;
+ unsigned int uy = py * PAGE_HEIGHT + offset / PAGE_WIDTH;
+ memcpy(x, &ux, sizeof(int));
+ memcpy(y, &uy, sizeof(int));
}
struct viewer *create_viewer(int fd, SDL_Renderer *renderer) {