summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blueshift_drm_c.c12
-rw-r--r--src/blueshift_drm_c.h14
-rw-r--r--src/blueshift_iccprofile.c12
-rw-r--r--src/blueshift_idcrtc.c10
-rw-r--r--src/blueshift_randr_c.c22
-rw-r--r--src/blueshift_randr_c.h6
6 files changed, 45 insertions, 31 deletions
diff --git a/src/blueshift_drm_c.c b/src/blueshift_drm_c.c
index 368991a..a900685 100644
--- a/src/blueshift_drm_c.c
+++ b/src/blueshift_drm_c.c
@@ -114,14 +114,14 @@ int blueshift_drm_open_card(int card_index)
}
if (card_connection_reuse_ptr)
- rc = *(card_connection_reusables + --card_connection_reuse_ptr);
+ rc = (int)*(card_connection_reusables + --card_connection_reuse_ptr);
else
{
if (card_connection_size == 0)
card_connections = malloc((card_connection_size = 8) * sizeof(card_connection));
else if (card_connection_ptr == card_connection_size)
card_connections = realloc(card_connections, (card_connection_size <<= 1) * sizeof(card_connection));
- rc = card_connection_ptr++;
+ rc = (int)(card_connection_ptr++);
}
(card_connections + rc)->fd = fd;
@@ -162,7 +162,7 @@ void blueshift_drm_close_card(int connection)
free(card->connectors);
close(card->fd);
- if ((size_t)connection + 1U == card_connection_reuse_ptr)
+ if ((size_t)connection + 1 == card_connection_reuse_ptr)
card_connection_reuse_ptr--;
else
{
@@ -422,10 +422,10 @@ long blueshift_drm_get_edid(int connection, int connector_index, char* edid, lon
drmModePropertyRes* prop = drmModeGetProperty(fd, connector->props[prop_i]);
if (!strcmp("EDID", prop->name))
{
- drmModePropertyBlobRes* blob = drmModeGetPropertyBlob(fd, connector->prop_values[prop_i]);
+ drmModePropertyBlobRes* blob = drmModeGetPropertyBlob(fd, (uint32_t)(connector->prop_values[prop_i]));
if (hexadecimal)
{
- uint32_t n = size / 2;
+ uint32_t n = (uint32_t)size / 2;
uint32_t i;
rc += blob->length;
if (n < blob->length)
@@ -438,7 +438,7 @@ long blueshift_drm_get_edid(int connection, int connector_index, char* edid, lon
}
else
{
- uint32_t len = blob->length < size ? blob->length : size;
+ uint32_t len = blob->length < size ? blob->length : (uint32_t)size;
memcpy(edid, blob->data, (size_t)len * sizeof(char));
}
drmModeFreePropertyBlob(blob);
diff --git a/src/blueshift_drm_c.h b/src/blueshift_drm_c.h
index e2e3757..527b205 100644
--- a/src/blueshift_drm_c.h
+++ b/src/blueshift_drm_c.h
@@ -101,7 +101,7 @@ void blueshift_drm_close_card(int connection);
* @param connection The identifier for the connection to the card
* @return The number of CRTC:s on the opened card
*/
-int blueshift_drm_crtc_count(int connection);
+int blueshift_drm_crtc_count(int connection) __attribute__((pure));
/**
* Return the number of connectors on the opened card
@@ -109,7 +109,7 @@ int blueshift_drm_crtc_count(int connection);
* @param connection The identifier for the connection to the card
* @return The number of connectors on the opened card
*/
-int blueshift_drm_connector_count(int connection);
+int blueshift_drm_connector_count(int connection) __attribute__((pure));
/**
* Return the size of the gamma ramps on a CRTC
@@ -169,7 +169,7 @@ void blueshift_drm_close_connector(int connection, int connector_index);
* @param connector_index The index of the connector
* @return The physical width of the monitor in millimetres, 0 if unknown or not connected
*/
-int blueshift_drm_get_width(int connection, int connector_index);
+int blueshift_drm_get_width(int connection, int connector_index) __attribute__((pure));
/**
* Get the physical height the monitor connected to a connector
@@ -178,7 +178,7 @@ int blueshift_drm_get_width(int connection, int connector_index);
* @param connector_index The index of the connector
* @return The physical height of the monitor in millimetres, 0 if unknown or not connected
*/
-int blueshift_drm_get_height(int connection, int connector_index);
+int blueshift_drm_get_height(int connection, int connector_index) __attribute__((pure));
/**
* Get whether a monitor is connected to a connector
@@ -187,7 +187,7 @@ int blueshift_drm_get_height(int connection, int connector_index);
* @param connector_index The index of the connector
* @return 1 if there is a connection, 0 otherwise, -1 if unknown
*/
-int blueshift_drm_is_connected(int connection, int connector_index);
+int blueshift_drm_is_connected(int connection, int connector_index) __attribute__((pure));
/**
* Get the index of the CRTC of the monitor connected to a connector
@@ -205,7 +205,7 @@ int blueshift_drm_get_crtc(int connection, int connector_index);
* @param connector_index The index of the connector
* @return The connector type by index, 0 for unknown
*/
-int blueshift_drm_get_connector_type_index(int connection, int connector_index);
+int blueshift_drm_get_connector_type_index(int connection, int connector_index) __attribute__((pure));
/**
* Get the name of the type of a connector
@@ -215,7 +215,7 @@ int blueshift_drm_get_connector_type_index(int connection, int connector_index);
* @return The connector type by name, "Unknown" if not identifiable,
* "Unrecognised" if Blueshift does not recognise it.
*/
-const char* blueshift_drm_get_connector_type_name(int connection, int connector_index);
+const char* blueshift_drm_get_connector_type_name(int connection, int connector_index) __attribute__((pure));
/**
* Get the extended display identification data for the monitor connected to a connector
diff --git a/src/blueshift_iccprofile.c b/src/blueshift_iccprofile.c
index 689a2da..99d5c42 100644
--- a/src/blueshift_iccprofile.c
+++ b/src/blueshift_iccprofile.c
@@ -42,11 +42,11 @@ static xcb_generic_error_t* error;
* @param argv Command line arguments
* @return Zero on success
*/
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wstack-protector"
-int main(int argc, char** argv)
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wstack-protector"
+int main(int argc, char **argv)
{
-#pragma GCC diagnostic pop
+ #pragma GCC diagnostic pop
char* display = NULL;
xcb_screen_iterator_t iter;
int screen_count;
@@ -128,7 +128,7 @@ int main(int argc, char** argv)
xcb_get_atom_name_reply_t* name_reply;
char* name;
char* name_;
- size_t len;
+ uint32_t len;
xcb_get_property_cookie_t prop_cookie;
xcb_get_property_reply_t* prop_reply;
int monitor;
@@ -154,7 +154,7 @@ int main(int argc, char** argv)
/* Extract the atom name from the data structure that holds it. */
name_ = xcb_get_atom_name_name(name_reply);
/* As well as the length of the name; it is not NUL-termianted.*/
- len = (size_t)xcb_get_atom_name_name_length(name_reply);
+ len = (uint32_t)xcb_get_atom_name_name_length(name_reply);
/* NUL-terminate the atom name, */
name = alloca((len + 1U) * sizeof(char));
diff --git a/src/blueshift_idcrtc.c b/src/blueshift_idcrtc.c
index 3979bf5..6bb0fff 100644
--- a/src/blueshift_idcrtc.c
+++ b/src/blueshift_idcrtc.c
@@ -28,12 +28,12 @@
/**
* The major version of RANDR the program expects
*/
-#define RANDR_VERSION_MAJOR 1U
+#define RANDR_VERSION_MAJOR 1
/**
* The minor version of RANDR the program expects
*/
-#define RANDR_VERSION_MINOR 3U
+#define RANDR_VERSION_MINOR 3
@@ -56,11 +56,11 @@ static xcb_generic_error_t* error;
* @param argv Command line arguments
* @return Zero on success
*/
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wstack-protector"
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wstack-protector"
int main(int argc, char** argv)
{
-#pragma GCC diagnostic pop
+ #pragma GCC diagnostic pop
char* display = NULL;
xcb_randr_query_version_cookie_t version_cookie;
xcb_randr_query_version_reply_t* randr_version;
diff --git a/src/blueshift_randr_c.c b/src/blueshift_randr_c.c
index 23035a3..0e38afc 100644
--- a/src/blueshift_randr_c.c
+++ b/src/blueshift_randr_c.c
@@ -201,11 +201,25 @@ uint16_t* blueshift_randr_read(int use_crtc)
G_size = xcb_randr_get_crtc_gamma_green_length(gamma_get_reply);
B_size = xcb_randr_get_crtc_gamma_blue_length(gamma_get_reply);
+ if ((R_size < 2) || (G_size < 2) || (B_size < 2))
+ {
+ fprintf(stderr, "RandR CRTC gamma query returned impossibly small ramps\n");
+ xcb_disconnect(connection);
+ return NULL;
+ }
+
+ if ((R_size | G_size | B_size) > UINT16_MAX)
+ {
+ fprintf(stderr, "RandR CRTC gamma query returned unexpectedly large ramps\n");
+ xcb_disconnect(connection);
+ return NULL;
+ }
+
R_gamma = xcb_randr_get_crtc_gamma_red(gamma_get_reply);
G_gamma = xcb_randr_get_crtc_gamma_green(gamma_get_reply);
B_gamma = xcb_randr_get_crtc_gamma_blue(gamma_get_reply);
- r_gamma = malloc((3U + (size_t)R_size + (size_t)G_size + (size_t)B_size) * sizeof(uint16_t));
+ r_gamma = malloc((3 + (size_t)R_size + (size_t)G_size + (size_t)B_size) * sizeof(uint16_t));
g_gamma = r_gamma + R_size + 1;
b_gamma = g_gamma + G_size + 1;
if (r_gamma == NULL)
@@ -216,9 +230,9 @@ uint16_t* blueshift_randr_read(int use_crtc)
return NULL;
}
- *r_gamma++ = R_size;
- *g_gamma++ = G_size;
- *b_gamma++ = B_size;
+ *r_gamma++ = (uint16_t)R_size;
+ *g_gamma++ = (uint16_t)G_size;
+ *b_gamma++ = (uint16_t)B_size;
for (i = 0; i < R_size; i++) *(r_gamma + i) = *(R_gamma + i);
for (i = 0; i < G_size; i++) *(g_gamma + i) = *(G_gamma + i);
diff --git a/src/blueshift_randr_c.h b/src/blueshift_randr_c.h
index 8ab21f3..2bc23f2 100644
--- a/src/blueshift_randr_c.h
+++ b/src/blueshift_randr_c.h
@@ -30,12 +30,12 @@
/**
* The major version of RandR the program expects
*/
-#define RANDR_VERSION_MAJOR 1U
+#define RANDR_VERSION_MAJOR 1
/**
* The minor version of RandR the program expects
*/
-#define RANDR_VERSION_MINOR 3U
+#define RANDR_VERSION_MINOR 3
@@ -47,7 +47,7 @@ typedef struct blueshift_randr_crtc
/**
* Size of colour curves on the X-axis
*/
- unsigned int curve_size;
+ uint16_t curve_size;
/**
* CRT controller