summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-16 08:58:55 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@ipe.fzk.de>2011-03-16 08:58:55 +0100
commit54a229b3864fe7867da69ef7427877094a256f1c (patch)
tree44b314944e24f3ef522360d76255bbc21ea36e12
parent98511f7a77e7b37f9508b66298d99d7d1103e422 (diff)
downloaduca-54a229b3864fe7867da69ef7427877094a256f1c.tar.gz
uca-54a229b3864fe7867da69ef7427877094a256f1c.tar.bz2
uca-54a229b3864fe7867da69ef7427877094a256f1c.tar.xz
uca-54a229b3864fe7867da69ef7427877094a256f1c.zip
Pass target string size when calling uca_get_property
-rw-r--r--src/cameras/ipe.c4
-rw-r--r--src/cameras/pco.c4
-rw-r--r--src/cameras/pf.c8
-rw-r--r--src/uca-cam.c2
-rw-r--r--src/uca-cam.h5
-rw-r--r--test/control.c15
-rw-r--r--test/enum.c9
-rw-r--r--test/grab.c6
8 files changed, 29 insertions, 24 deletions
diff --git a/src/cameras/ipe.c b/src/cameras/ipe.c
index d1a331c..d6a8f8e 100644
--- a/src/cameras/ipe.c
+++ b/src/cameras/ipe.c
@@ -19,14 +19,14 @@ static uint32_t uca_ipe_set_property(struct uca_camera_t *cam, enum uca_property
return UCA_NO_ERROR;
}
-static uint32_t uca_ipe_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data)
+static uint32_t uca_ipe_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data, size_t num)
{
pcilib_t *handle = GET_HANDLE(cam);
pcilib_register_value_t value = 0;
switch (property) {
case UCA_PROP_NAME:
- strcpy((char *) data, "IPE PCIe based on CMOSIS CMV2000");
+ strncpy((char *) data, "IPE PCIe based on CMOSIS CMV2000", bytes);
break;
case UCA_PROP_WIDTH:
diff --git a/src/cameras/pco.c b/src/cameras/pco.c
index 4f793dc..a789762 100644
--- a/src/cameras/pco.c
+++ b/src/cameras/pco.c
@@ -82,7 +82,7 @@ static uint32_t uca_pco_set_property(struct uca_camera_t *cam, enum uca_property
}
-static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data)
+static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data, size_t num)
{
struct pco_edge_t *pco = GET_PCO(cam);
struct uca_grabber_t *grabber = cam->grabber;
@@ -99,7 +99,7 @@ static uint32_t uca_pco_get_property(struct uca_camera_t *cam, enum uca_property
* one.*/
pco_read_property(pco, GET_CAMERA_NAME, &name, sizeof(name));
pco_read_property(pco, GET_CAMERA_NAME, &name, sizeof(name));
- strcpy((char *) data, name.szName);
+ strncpy((char *) data, name.szName, num);
}
break;
diff --git a/src/cameras/pf.c b/src/cameras/pf.c
index 5b0679e..c1267e3 100644
--- a/src/cameras/pf.c
+++ b/src/cameras/pf.c
@@ -107,7 +107,7 @@ static uint32_t uca_pf_set_property(struct uca_camera_t *cam, enum uca_property_
}
-static uint32_t uca_pf_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data)
+static uint32_t uca_pf_get_property(struct uca_camera_t *cam, enum uca_property_ids property, void *data, size_t num)
{
TOKEN t; /* You gotta love developers who name types capitalized... */
PFValue value;
@@ -133,7 +133,7 @@ static uint32_t uca_pf_get_property(struct uca_camera_t *cam, enum uca_property_
set_void(data, uint32_t, (uint32_t) floor(atof(value.value.p)+0.5));
}
else {
- strcpy((char *) data, value.value.p);
+ strncpy((char *) data, value.value.p, num);
}
break;
@@ -219,8 +219,8 @@ uint32_t uca_pf_init(struct uca_camera_t **cam, struct uca_grabber_t *grabber)
val = UCA_TRIGGER_FREERUN;
grabber->set_property(grabber, UCA_GRABBER_TRIGGER_MODE, &val);
- uca_pf_get_property(uca, UCA_PROP_WIDTH, &uca->frame_width);
- uca_pf_get_property(uca, UCA_PROP_HEIGHT, &uca->frame_height);
+ uca_pf_get_property(uca, UCA_PROP_WIDTH, &uca->frame_width, 0);
+ uca_pf_get_property(uca, UCA_PROP_HEIGHT, &uca->frame_height, 0);
grabber->set_property(grabber, UCA_GRABBER_WIDTH, &uca->frame_width);
grabber->set_property(grabber, UCA_GRABBER_HEIGHT, &uca->frame_height);
diff --git a/src/uca-cam.c b/src/uca-cam.c
index 5d7741d..7c351d1 100644
--- a/src/uca-cam.c
+++ b/src/uca-cam.c
@@ -7,7 +7,7 @@
uint32_t uca_cam_alloc(struct uca_camera_t *cam, uint32_t n_buffers)
{
uint32_t bitdepth;
- cam->get_property(cam, UCA_PROP_BITDEPTH, &bitdepth);
+ cam->get_property(cam, UCA_PROP_BITDEPTH, &bitdepth, 0);
const int pixel_size = bitdepth == 8 ? 1 : 2;
if (cam->grabber != NULL)
return cam->grabber->alloc(cam->grabber, pixel_size, n_buffers);
diff --git a/src/uca-cam.h b/src/uca-cam.h
index 7a18b3d..f668e54 100644
--- a/src/uca-cam.h
+++ b/src/uca-cam.h
@@ -113,9 +113,12 @@ typedef uint32_t (*uca_cam_set_property) (struct uca_camera_t *cam, enum uca_pro
*
* \param[out] data Where to store the property's value
*
+ * \param[in] num Number of bytes of string storage. Ignored for uca_uint8t
+ * and uca_uint32t properties.
+ *
* \return UCA_ERR_PROP_INVALID if property is not supported on the camera
*/
-typedef uint32_t (*uca_cam_get_property) (struct uca_camera_t *cam, enum uca_property_ids property, void *data);
+typedef uint32_t (*uca_cam_get_property) (struct uca_camera_t *cam, enum uca_property_ids property, void *data, size_t num);
/**
* Begin recording.
diff --git a/test/control.c b/test/control.c
index a8c7079..6024c08 100644
--- a/test/control.c
+++ b/test/control.c
@@ -206,7 +206,8 @@ void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera_t *cam)
{
GtkTreeIter iter, child;
struct uca_property_t *property;
- gchar *value_string = g_malloc(256);
+ const size_t num_bytes = 256;
+ gchar *value_string = g_malloc(num_bytes);
guint8 value_8;
guint32 value_32;
@@ -215,16 +216,16 @@ void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera_t *cam)
uint32_t result = UCA_NO_ERROR;
switch (property->type) {
case uca_string:
- result = cam->get_property(cam, prop_id, value_string);
+ result = cam->get_property(cam, prop_id, value_string, num_bytes);
break;
case uca_uint8t:
- result = cam->get_property(cam, prop_id, &value_8);
+ result = cam->get_property(cam, prop_id, &value_8, 0);
g_sprintf(value_string, "%d", value_8);
break;
case uca_uint32t:
- result = cam->get_property(cam, prop_id, &value_32);
+ result = cam->get_property(cam, prop_id, &value_32, 0);
g_sprintf(value_string, "%d", value_32);
break;
}
@@ -281,9 +282,9 @@ int main(int argc, char *argv[])
int width, height, bits_per_sample;
struct uca_camera_t *cam = uca->cameras;
- cam->get_property(cam, UCA_PROP_WIDTH, &width);
- cam->get_property(cam, UCA_PROP_HEIGHT, &height);
- cam->get_property(cam, UCA_PROP_BITDEPTH, &bits_per_sample);
+ cam->get_property(cam, UCA_PROP_WIDTH, &width, 0);
+ cam->get_property(cam, UCA_PROP_HEIGHT, &height, 0);
+ cam->get_property(cam, UCA_PROP_BITDEPTH, &bits_per_sample, 0);
g_thread_init(NULL);
gdk_threads_init();
diff --git a/test/enum.c b/test/enum.c
index 8803ec4..1164399 100644
--- a/test/enum.c
+++ b/test/enum.c
@@ -30,7 +30,8 @@ int main(int argc, char *argv[])
/* take first camera */
struct uca_camera_t *cam = uca->cameras;
- char string_value[256];
+ const size_t num_bytes = 256;
+ char string_value[num_bytes];
uint32_t uint32_value;
uint8_t uint8_value;
@@ -41,21 +42,21 @@ int main(int argc, char *argv[])
printf("%s = ", prop->name);
switch (prop->type) {
case uca_string:
- if (cam->get_property(cam, i, string_value) != UCA_ERR_PROP_INVALID) {
+ if (cam->get_property(cam, i, string_value, num_bytes) != UCA_ERR_PROP_INVALID) {
printf("%s ", string_value);
}
else
printf("n/a");
break;
case uca_uint32t:
- if (cam->get_property(cam, i, &uint32_value) != UCA_ERR_PROP_INVALID) {
+ if (cam->get_property(cam, i, &uint32_value, 0) != UCA_ERR_PROP_INVALID) {
printf("%i %s", uint32_value, uca_unit_map[prop->unit]);
}
else
printf("n/a");
break;
case uca_uint8t:
- if (cam->get_property(cam, i, &uint8_value) != UCA_ERR_PROP_INVALID) {
+ if (cam->get_property(cam, i, &uint8_value, 0) != UCA_ERR_PROP_INVALID) {
printf("%i %s", uint8_value, uca_unit_map[prop->unit]);
}
else
diff --git a/test/grab.c b/test/grab.c
index 5ae44f1..6f646c7 100644
--- a/test/grab.c
+++ b/test/grab.c
@@ -21,9 +21,9 @@ int main(int argc, char *argv[])
cam->set_property(cam, UCA_PROP_DELAY, &val);
uint32_t width, height, bits;
- cam->get_property(cam, UCA_PROP_WIDTH, &width);
- cam->get_property(cam, UCA_PROP_HEIGHT, &height);
- cam->get_property(cam, UCA_PROP_BITDEPTH, &bits);
+ cam->get_property(cam, UCA_PROP_WIDTH, &width, 0);
+ cam->get_property(cam, UCA_PROP_HEIGHT, &height, 0);
+ cam->get_property(cam, UCA_PROP_BITDEPTH, &bits, 0);
uca_cam_alloc(cam, 10);