[aravis] all: avoid pointer arithmetic on void pointers.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] all: avoid pointer arithmetic on void pointers.
- Date: Sun, 28 Apr 2013 13:28:57 +0000 (UTC)
commit 02c25527d45c39f29f3d4d80aeed7033b220c6b2
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Sun Apr 28 15:28:17 2013 +0200
all: avoid pointer arithmetic on void pointers.
It's a gcc extension.
INSTALL | 2 +-
gst/gstaravis.c | 2 +-
src/arvfakecamera.c | 18 +++++++++---------
src/arvfakegvcamera.c | 2 +-
src/arvgcregisternode.c | 4 ++--
src/arvgvdevice.c | 4 ++--
src/arvgvstream.c | 2 +-
src/arvmisc.c | 14 +++++++-------
src/arvzip.c | 34 +++++++++++++++++-----------------
src/arvzip.h | 14 ++++++++++----
tests/misc.c | 16 ++++++++--------
viewer/arvviewer.c | 2 +-
12 files changed, 60 insertions(+), 54 deletions(-)
---
diff --git a/INSTALL b/INSTALL
index a47e36f..8b641e3 120000
--- a/INSTALL
+++ b/INSTALL
@@ -1 +1 @@
-/usr/share/automake-1.12/INSTALL
\ No newline at end of file
+/usr/share/automake-1.13/INSTALL
\ No newline at end of file
diff --git a/gst/gstaravis.c b/gst/gstaravis.c
index f4046c8..0e6f0a8 100644
--- a/gst/gstaravis.c
+++ b/gst/gstaravis.c
@@ -344,7 +344,7 @@ gst_aravis_create (GstPushSrc * push_src, GstBuffer ** buffer)
data = g_malloc (size);
for (i = 0; i < arv_buffer->height; i++)
- memcpy (data + i * gst_row_stride, arv_buffer->data + i * arv_row_stride,
arv_row_stride);
+ memcpy (((char *) data) + i * gst_row_stride, ((char *) arv_buffer->data) + i *
arv_row_stride, arv_row_stride);
GST_BUFFER_DATA (buffer) = data;
GST_BUFFER_MALLOCDATA (buffer) = data;
diff --git a/src/arvfakecamera.c b/src/arvfakecamera.c
index 9876876..07e421a 100644
--- a/src/arvfakecamera.c
+++ b/src/arvfakecamera.c
@@ -75,7 +75,7 @@ arv_fake_camera_read_memory (ArvFakeCamera *camera, guint32 address, guint32 siz
if (address < ARV_FAKE_CAMERA_MEMORY_SIZE) {
g_return_val_if_fail (address + size < ARV_FAKE_CAMERA_MEMORY_SIZE, FALSE);
- memcpy (buffer, camera->priv->memory + address, size);
+ memcpy (buffer, ((char *) camera->priv->memory) + address, size);
return TRUE;
}
@@ -83,7 +83,7 @@ arv_fake_camera_read_memory (ArvFakeCamera *camera, guint32 address, guint32 siz
address -= ARV_FAKE_CAMERA_MEMORY_SIZE;
read_size = MIN (address + size, camera->priv->genicam_xml_size) - address;
- memcpy (buffer, camera->priv->genicam_xml + address, read_size);
+ memcpy (buffer, ((char *) camera->priv->genicam_xml) + address, read_size);
return TRUE;
}
@@ -100,7 +100,7 @@ arv_fake_camera_write_memory (ArvFakeCamera *camera, guint32 address, guint32 si
if (address + size > ARV_FAKE_CAMERA_MEMORY_SIZE)
return FALSE;
- memcpy (camera->priv->memory + address, buffer, size);
+ memcpy (((char *) camera->priv->memory) + address, buffer, size);
return TRUE;
}
@@ -136,7 +136,7 @@ _get_register (ArvFakeCamera *camera, guint32 address)
if (address + sizeof (guint32) > ARV_FAKE_CAMERA_MEMORY_SIZE)
return 0;
- value = *((guint32 *) ((void*) (camera->priv->memory + address)));
+ value = *((guint32 *) (((char *)(camera->priv->memory) + address)));
return GUINT32_FROM_BE (value);
}
@@ -440,16 +440,16 @@ arv_fake_camera_new (const char *serial_number)
fake_camera->priv->genicam_xml = arv_get_fake_camera_genicam_xml
(&fake_camera->priv->genicam_xml_size);
fake_camera->priv->memory = memory;
- strcpy (memory + ARV_GVBS_MANUFACTURER_NAME_OFFSET, "Aravis");
- strcpy (memory + ARV_GVBS_MODEL_NAME_OFFSET, "Fake");
- strcpy (memory + ARV_GVBS_DEVICE_VERSION_OFFSET, PACKAGE_VERSION);
- strcpy (memory + ARV_GVBS_SERIAL_NUMBER_OFFSET, serial_number);
+ strcpy (((char *) memory) + ARV_GVBS_MANUFACTURER_NAME_OFFSET, "Aravis");
+ strcpy (((char *) memory) + ARV_GVBS_MODEL_NAME_OFFSET, "Fake");
+ strcpy (((char *) memory) + ARV_GVBS_DEVICE_VERSION_OFFSET, PACKAGE_VERSION);
+ strcpy (((char *) memory) + ARV_GVBS_SERIAL_NUMBER_OFFSET, serial_number);
xml_url = g_strdup_printf ("Local:arv-fake-camera-%s.xml;%x;%x",
PACKAGE_VERSION,
ARV_FAKE_CAMERA_MEMORY_SIZE,
(unsigned int) fake_camera->priv->genicam_xml_size);
- strcpy (memory + ARV_GVBS_XML_URL_0_OFFSET, xml_url);
+ strcpy (((char *) memory) + ARV_GVBS_XML_URL_0_OFFSET, xml_url);
g_free (xml_url);
arv_fake_camera_write_register (fake_camera, ARV_FAKE_CAMERA_REGISTER_SENSOR_WIDTH,
diff --git a/src/arvfakegvcamera.c b/src/arvfakegvcamera.c
index 4680eb8..699a866 100644
--- a/src/arvfakegvcamera.c
+++ b/src/arvfakegvcamera.c
@@ -165,7 +165,7 @@ arv_fake_gv_camera_thread (void *user_data)
packet_size = ARV_FAKE_GV_CAMERA_BUFFER_SIZE;
arv_gvsp_packet_new_data_block (image_buffer->frame_id, block_id,
- data_size, image_buffer->data + offset,
+ data_size, ((char *) image_buffer->data) +
offset,
packet_buffer, &packet_size);
g_socket_send_to (gv_camera->gvsp_socket, stream_address,
diff --git a/src/arvgcregisternode.c b/src/arvgcregisternode.c
index 83b19e6..54084f3 100644
--- a/src/arvgcregisternode.c
+++ b/src/arvgcregisternode.c
@@ -620,7 +620,7 @@ arv_gc_register_node_get (ArvGcRegister *gc_register, void *buffer, guint64 leng
if (length > gc_register_node->cache_size) {
memcpy (buffer, gc_register_node->cache, gc_register_node->cache_size);
- memset (buffer + gc_register_node->cache_size, 0, length - gc_register_node->cache_size);
+ memset (((char *) buffer) + gc_register_node->cache_size, 0, length -
gc_register_node->cache_size);
} else
memcpy (buffer, gc_register_node->cache, length);
@@ -635,7 +635,7 @@ arv_gc_register_node_set (ArvGcRegister *gc_register, void *buffer, guint64 leng
if (gc_register_node->cache_size > length) {
memcpy (gc_register_node->cache, buffer, length);
- memset (gc_register_node->cache + length, 0, gc_register_node->cache_size - length);
+ memset (((char *) gc_register_node->cache) + length, 0, gc_register_node->cache_size -
length);
} else
memcpy (gc_register_node->cache, buffer, gc_register_node->cache_size);
diff --git a/src/arvgvdevice.c b/src/arvgvdevice.c
index c06ef04..8af102a 100644
--- a/src/arvgvdevice.c
+++ b/src/arvgvdevice.c
@@ -771,7 +771,7 @@ arv_gv_device_read_memory (ArvDevice *device, guint32 address, guint32 size, voi
block_size = MIN (ARV_GVCP_DATA_SIZE_MAX, size - i * ARV_GVCP_DATA_SIZE_MAX);
if (!_read_memory (gv_device->priv->io_data,
address + i * ARV_GVCP_DATA_SIZE_MAX,
- block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX, error))
+ block_size, ((char *) buffer) + i * ARV_GVCP_DATA_SIZE_MAX, error))
return FALSE;
}
@@ -789,7 +789,7 @@ arv_gv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, vo
block_size = MIN (ARV_GVCP_DATA_SIZE_MAX, size - i * ARV_GVCP_DATA_SIZE_MAX);
if (!_write_memory (gv_device->priv->io_data,
address + i * ARV_GVCP_DATA_SIZE_MAX,
- block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX, error))
+ block_size, ((char *) buffer) + i * ARV_GVCP_DATA_SIZE_MAX, error))
return FALSE;
}
diff --git a/src/arvgvstream.c b/src/arvgvstream.c
index 40707f9..b295c7d 100644
--- a/src/arvgvstream.c
+++ b/src/arvgvstream.c
@@ -255,7 +255,7 @@ _process_data_block (ArvGvStreamThreadData *thread_data,
block_size = block_end - block_offset;
}
- memcpy (frame->buffer->data + block_offset, &packet->data, block_size);
+ memcpy (((char *) frame->buffer->data) + block_offset, &packet->data, block_size);
if (frame->packet_data[packet_id].time_us > 0) {
thread_data->n_resent_packets++;
diff --git a/src/arvmisc.c b/src/arvmisc.c
index b82e085..e1972dc 100644
--- a/src/arvmisc.c
+++ b/src/arvmisc.c
@@ -437,18 +437,18 @@ arv_copy_memory_with_endianess (void *to, size_t to_size, guint to_endianess,
if (to_endianess == G_LITTLE_ENDIAN &&
from_endianess == G_BIG_ENDIAN) {
to_ptr = to;
- from_ptr = from + from_size - 1;
+ from_ptr = ((char *) from) + from_size - 1;
if (to_size <= from_size) {
for (i = 0; i < to_size; i++, to_ptr++, from_ptr--)
*to_ptr = *from_ptr;
} else {
for (i = 0; i < from_size; i++, to_ptr++, from_ptr--)
*to_ptr = *from_ptr;
- memset (to + from_size, 0, to_size - from_size);
+ memset (((char *) to) + from_size, 0, to_size - from_size);
}
} else if (to_endianess == G_BIG_ENDIAN &&
from_endianess == G_LITTLE_ENDIAN) {
- to_ptr = to + to_size - 1;
+ to_ptr = ((char *) to) + to_size - 1;
from_ptr = from;
if (to_size <= from_size) {
for (i = 0; i < to_size; i++, to_ptr--, from_ptr++)
@@ -464,14 +464,14 @@ arv_copy_memory_with_endianess (void *to, size_t to_size, guint to_endianess,
memcpy (to, from, to_size);
else {
memcpy (to, from, from_size);
- memset (to + from_size, 0, to_size - from_size);
+ memset (((char *) to) + from_size, 0, to_size - from_size);
}
} else if (to_endianess == G_BIG_ENDIAN &&
from_endianess == G_BIG_ENDIAN) {
if (to_size <= from_size)
- memcpy (to, from + from_size - to_size, to_size);
+ memcpy (to, ((char *) from) + from_size - to_size, to_size);
else {
- memcpy (to + to_size - from_size, from, from_size);
+ memcpy (((char *) to) + to_size - from_size, from, from_size);
memset (to, 0, to_size - from_size);
}
} else
@@ -521,7 +521,7 @@ arv_decompress (void *input_buffer, size_t input_size, size_t *output_size)
stream.next_in, stream.avail_in, *stream.next_in);
input_size -= stream.avail_in;
- input_buffer += stream.avail_in;
+ input_buffer = ((char *) input_buffer) + stream.avail_in;
/* run inflate() on input until output buffer not full */
do {
diff --git a/src/arvzip.c b/src/arvzip.c
index 891b1a0..a88dfde 100644
--- a/src/arvzip.c
+++ b/src/arvzip.c
@@ -1,6 +1,6 @@
/* Aravis - Digital camera library
*
- * Copyright © 2009-2010 Emmanuel Pacaud
+ * Copyright © 2009-2013 Emmanuel Pacaud
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -84,27 +84,27 @@ arv_zip_build_file_list (ArvZip *zip)
for (i = 0; i < zip->n_files; i++) {
ptr = zip->buffer + zip->header_size + offset;
- if (ARV_GUINT32_FROM_LE_PTR (ptr) != 0x02014b50) {
+ if (ARV_GUINT32_FROM_LE_PTR (ptr, 0) != 0x02014b50) {
arv_debug_misc ("[Zip::build_file_list] Magic number of central directory not found
(0x02014b50)");
arv_debug_misc ("[Zip::build_file_list] Expected at 0x%08x - found 0x%08x instead",
- zip->header_size + offset, ARV_GUINT32_FROM_LE_PTR (ptr));
+ zip->header_size + offset, ARV_GUINT32_FROM_LE_PTR (ptr, 0));
return;
}
zip_file = g_new0 (ArvZipFile, 1);
- zip_file->compressed_size = ARV_GUINT32_FROM_LE_PTR (ptr + 20);
- zip_file->uncompressed_size = ARV_GUINT32_FROM_LE_PTR (ptr + 24);
- zip_file->offset = ARV_GUINT32_FROM_LE_PTR (ptr + 42);
- zip_file->name = g_strndup ((char *) (ptr + 46), ARV_GUINT16_FROM_LE_PTR (ptr + 28));
+ zip_file->compressed_size = ARV_GUINT32_FROM_LE_PTR (ptr, 20);
+ zip_file->uncompressed_size = ARV_GUINT32_FROM_LE_PTR (ptr, 24);
+ zip_file->offset = ARV_GUINT32_FROM_LE_PTR (ptr, 42);
+ zip_file->name = g_strndup (((char *) ptr) + 46, ARV_GUINT16_FROM_LE_PTR (ptr, 28));
arv_log_misc ("[Zip::list_files] %s", zip_file->name);
zip->files = g_slist_prepend (zip->files, zip_file);
offset += 0x2e +
- ARV_GUINT16_FROM_LE_PTR (ptr + 28) + /* filename size */
- ARV_GUINT16_FROM_LE_PTR (ptr + 30) + /* extra field */
- ARV_GUINT16_FROM_LE_PTR (ptr + 32); /* file comment */
+ ARV_GUINT16_FROM_LE_PTR (ptr, 28) + /* filename size */
+ ARV_GUINT16_FROM_LE_PTR (ptr, 30) + /* extra field */
+ ARV_GUINT16_FROM_LE_PTR (ptr, 32); /* file comment */
}
}
@@ -130,14 +130,14 @@ arv_zip_get_file_data (ArvZip *zip, ArvZipFile *zip_file)
ptr = zip->buffer + zip_file->offset + zip->header_size;
- if (ARV_GUINT32_FROM_LE_PTR (ptr) != 0x04034b50) {
+ if (ARV_GUINT32_FROM_LE_PTR (ptr, 0) != 0x04034b50) {
arv_debug_misc ("[Zip::get_file_data] Magic number for file header not found (0x04034b50)");
return -1;
}
return zip_file->offset + zip->header_size +
- ARV_GUINT16_FROM_LE_PTR (ptr + 26) +
- ARV_GUINT16_FROM_LE_PTR (ptr + 28) + 30;
+ ARV_GUINT16_FROM_LE_PTR (ptr, 26) +
+ ARV_GUINT16_FROM_LE_PTR (ptr, 28) + 30;
}
/**
@@ -179,15 +179,15 @@ arv_zip_new (const void *buffer, size_t size)
}
ptr = zip->buffer + zip->directory_position;
- zip->n_files = ARV_GUINT16_FROM_LE_PTR (ptr + 10);
- if (ARV_GUINT16_FROM_LE_PTR (ptr + 8) != zip->n_files) {
+ zip->n_files = ARV_GUINT16_FROM_LE_PTR (ptr, 10);
+ if (ARV_GUINT16_FROM_LE_PTR (ptr, 8) != zip->n_files) {
arv_debug_misc ("[Zip::new] Mismatch in number of files");
zip->n_files = 0;
return zip;
}
- zip->directory_size = ARV_GUINT32_FROM_LE_PTR (ptr + 12);
- zip->directory_offset = ARV_GUINT32_FROM_LE_PTR (ptr + 16);
+ zip->directory_size = ARV_GUINT32_FROM_LE_PTR (ptr, 12);
+ zip->directory_offset = ARV_GUINT32_FROM_LE_PTR (ptr, 16);
zip->header_size = zip->directory_position - (zip->directory_offset + zip->directory_size);
arv_log_misc ("[Zip::new] number of files = %d", zip->n_files);
diff --git a/src/arvzip.h b/src/arvzip.h
index bcb9e07..ecad005 100644
--- a/src/arvzip.h
+++ b/src/arvzip.h
@@ -35,12 +35,13 @@ const GSList * arv_zip_get_file_list (ArvZip *zip);
const char * arv_zip_file_get_name (ArvZipFile *zip_file);
size_t arv_zip_file_get_uncompressed_size (ArvZipFile *zip_file);
-#define ARV_GUINT32_FROM_LE_PTR(ptr) arv_guint32_from_unaligned_le_ptr (ptr)
-#define ARV_GUINT16_FROM_LE_PTR(ptr) arv_guint16_from_unaligned_le_ptr (ptr)
+#define ARV_GUINT32_FROM_LE_PTR(ptr,offset) arv_guint32_from_unaligned_le_ptr (ptr, offset)
+#define ARV_GUINT16_FROM_LE_PTR(ptr,offset) arv_guint16_from_unaligned_le_ptr (ptr, offset)
/**
* arv_guint32_from_unaligned_le_ptr:
* @ptr: pointer to a little endian 32 bit usigned integer
+ * @offset: an offset to add to @ptr
*
* Here's an excerpt of the ARM documentation:
*
@@ -67,12 +68,14 @@ size_t arv_zip_file_get_uncompressed_size (ArvZipFile *zip_file);
*/
static inline guint32
-arv_guint32_from_unaligned_le_ptr (const void *ptr)
+arv_guint32_from_unaligned_le_ptr (const char *ptr, gint32 offset)
{
guint32 val;
g_return_val_if_fail (ptr != NULL, 0);
+ ptr += offset;
+
*((char*)(&val)) = *((char*)ptr);
*(((char*)(&val))+1) = *(((char*)ptr)+1);
*(((char*)(&val))+2) = *(((char*)ptr)+2);
@@ -84,6 +87,7 @@ arv_guint32_from_unaligned_le_ptr (const void *ptr)
/**
* arv_guint16_from_unaligned_le_ptr:
* @ptr: pointer to a little endian 16 bit usigned integer
+ * @offset: an offset to add to @ptr
*
* See @arv_guint32_from_unaligned_le_ptr.
*
@@ -91,12 +95,14 @@ arv_guint32_from_unaligned_le_ptr (const void *ptr)
*/
static inline guint16
-arv_guint16_from_unaligned_le_ptr (const void *ptr)
+arv_guint16_from_unaligned_le_ptr (const char *ptr, gint16 offset)
{
guint16 val;
g_return_val_if_fail (ptr != NULL, 0);
+ ptr += offset;
+
*((char*)(&val)) = *((char*)ptr);
*(((char*)(&val))+1) = *(((char*)ptr)+1);
diff --git a/tests/misc.c b/tests/misc.c
index 6ec846d..b088000 100644
--- a/tests/misc.c
+++ b/tests/misc.c
@@ -9,28 +9,28 @@ unaligned_from_le_ptr_test (void)
guint32 v_uint32;
guint16 v_uint16;
- v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[0]);
+ v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[0], 0);
g_assert_cmpuint (v_uint32, ==, 0x44332211);
- v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[1]);
+ v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[1], 0);
g_assert_cmpuint (v_uint32, ==, 0x55443322);
- v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[2]);
+ v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[2], 0);
g_assert_cmpuint (v_uint32, ==, 0x66554433);
- v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[3]);
+ v_uint32 = ARV_GUINT32_FROM_LE_PTR (&test[3], 0);
g_assert_cmpuint (v_uint32, ==, 0x77665544);
- v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[0]);
+ v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[0], 0);
g_assert_cmpuint (v_uint16, ==, 0x2211);
- v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[1]);
+ v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[1], 0);
g_assert_cmpuint (v_uint16, ==, 0x3322);
- v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[2]);
+ v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[2], 0);
g_assert_cmpuint (v_uint16, ==, 0x4433);
- v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[3]);
+ v_uint16 = ARV_GUINT16_FROM_LE_PTR (&test[3], 0);
g_assert_cmpuint (v_uint16, ==, 0x5544);
}
diff --git a/viewer/arvviewer.c b/viewer/arvviewer.c
index 9ab270c..0c8a1af 100644
--- a/viewer/arvviewer.c
+++ b/viewer/arvviewer.c
@@ -173,7 +173,7 @@ arv_viewer_new_buffer_cb (ArvStream *stream, ArvViewer *viewer)
data = g_malloc (size);
for (i = 0; i < arv_buffer->height; i++)
- memcpy (data + i * gst_row_stride, arv_buffer->data + i * arv_row_stride,
arv_row_stride);
+ memcpy (((char *) data) + i * gst_row_stride, ((char *) arv_buffer->data) + i
* arv_row_stride, arv_row_stride);
GST_BUFFER_DATA (buffer) = data;
GST_BUFFER_MALLOCDATA (buffer) = data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]