util: Fix some truncation warnings, mostly by explicitly casting

This commit is contained in:
Ryan Pavlik 2021-09-20 10:28:41 -05:00
parent 5f8cb4e227
commit d4d6a1a73f
2 changed files with 11 additions and 9 deletions

View file

@ -19,7 +19,8 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
/*
@ -325,6 +326,7 @@ u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t num_xdevs, int *hea
*head = XRT_DEVICE_ROLE_UNASSIGNED;
*left = XRT_DEVICE_ROLE_UNASSIGNED;
*right = XRT_DEVICE_ROLE_UNASSIGNED;
assert(num_xdevs < INT_MAX);
for (size_t i = 0; i < num_xdevs; i++) {
if (xdevs[i] == NULL) {
@ -334,26 +336,26 @@ u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t num_xdevs, int *hea
switch (xdevs[i]->device_type) {
case XRT_DEVICE_TYPE_HMD:
if (*head == XRT_DEVICE_ROLE_UNASSIGNED) {
*head = i;
*head = (int)i;
}
break;
case XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER:
try_move_assignment(xdevs, left, right);
if (*left == XRT_DEVICE_ROLE_UNASSIGNED) {
*left = i;
*left = (int)i;
}
break;
case XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER:
try_move_assignment(xdevs, right, left);
if (*right == XRT_DEVICE_ROLE_UNASSIGNED) {
*right = i;
*right = (int)i;
}
break;
case XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER:
if (*left == XRT_DEVICE_ROLE_UNASSIGNED) {
*left = i;
*left = (int)i;
} else if (*right == XRT_DEVICE_ROLE_UNASSIGNED) {
*right = i;
*right = (int)i;
} else {
//! @todo: do something with unassigend devices?
}
@ -369,10 +371,10 @@ u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t num_xdevs, int *hea
}
if (xdevs[i]->device_type == XRT_DEVICE_TYPE_HAND_TRACKER) {
if (*left == XRT_DEVICE_ROLE_UNASSIGNED) {
*left = i;
*left = (int)i;
}
if (*right == XRT_DEVICE_ROLE_UNASSIGNED) {
*right = i;
*right = (int)i;
}
break;
}

View file

@ -71,7 +71,7 @@ u_distortion_cardboard_calculate(const struct u_cardboard_distortion_arguments *
l_values.distortion_k[4] = args->distortion_k[4];
l_values.screen.size.x = args->screen.w_meters;
l_values.screen.size.y = args->screen.h_meters;
l_values.screen.offset.x = (args->screen.w_meters - args->inter_lens_distance_meters) / 2.0;
l_values.screen.offset.x = (args->screen.w_meters - args->inter_lens_distance_meters) / 2.0f;
l_values.screen.offset.y = args->lens_y_center_on_screen_meters;
// clang-format on