summaryrefslogtreecommitdiff
path: root/libgphoto2
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2014-07-21 20:44:18 +0000
committerMarcus Meissner <marcus@jet.franken.de>2014-07-21 20:44:18 +0000
commitb0d404cae50bd0aff73a73c3722cc3cfb81e7d25 (patch)
tree257525aaf8d727054bc00553d84226113125817d /libgphoto2
parentb04b755500defcb12d4152db13dc52fbdfa8f443 (diff)
downloadlibgphoto2-b0d404cae50bd0aff73a73c3722cc3cfb81e7d25.tar.gz
From: Axel Waggershauser <awagger@web.de>
3) use the fact that realloc() is defined to simply malloc if the first param is NULL, no need to manually distinguish between first and later allocations. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15098 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'libgphoto2')
-rw-r--r--libgphoto2/gphoto2-abilities-list.c10
-rw-r--r--libgphoto2/gphoto2-camera.c5
-rw-r--r--libgphoto2/gphoto2-file.c6
-rw-r--r--libgphoto2/gphoto2-widget.c23
4 files changed, 8 insertions, 36 deletions
diff --git a/libgphoto2/gphoto2-abilities-list.c b/libgphoto2/gphoto2-abilities-list.c
index 3f056bdb2..4aad66f95 100644
--- a/libgphoto2/gphoto2-abilities-list.c
+++ b/libgphoto2/gphoto2-abilities-list.c
@@ -511,16 +511,10 @@ remove_colon_from_string (char *str)
int
gp_abilities_list_append (CameraAbilitiesList *list, CameraAbilities abilities)
{
- CameraAbilities *new_abilities;
-
CHECK_NULL (list);
- if (!list->count)
- C_MEM( new_abilities = malloc (sizeof (CameraAbilities)) );
- else
- C_MEM (new_abilities = realloc (list->abilities,
- sizeof (CameraAbilities) * (list->count + 1)));
- list->abilities = new_abilities;
+ C_MEM (list->abilities = realloc (list->abilities,
+ sizeof (CameraAbilities) * (list->count + 1)));
memcpy (&(list->abilities [list->count]), &abilities,
sizeof (CameraAbilities));
diff --git a/libgphoto2/gphoto2-camera.c b/libgphoto2/gphoto2-camera.c
index f8c6f2348..cfe97ae15 100644
--- a/libgphoto2/gphoto2-camera.c
+++ b/libgphoto2/gphoto2-camera.c
@@ -1593,7 +1593,6 @@ gp_camera_start_timeout (Camera *camera, unsigned int timeout,
CameraTimeoutFunc func)
{
int id;
- unsigned int *ids;
if (!camera || !camera->pc)
return (GP_ERROR_BAD_PARAMETERS);
@@ -1605,9 +1604,9 @@ gp_camera_start_timeout (Camera *camera, unsigned int timeout,
* We remember the id here in order to automatically remove
* the timeout on gp_camera_exit.
*/
- C_MEM (ids = realloc (camera->pc->timeout_ids, sizeof (int) *
+ C_MEM (camera->pc->timeout_ids =
+ realloc (camera->pc->timeout_ids, sizeof (int) *
(camera->pc->timeout_ids_len + 1)));
- camera->pc->timeout_ids = ids;
id = camera->pc->timeout_start_func (camera, timeout, func,
camera->pc->timeout_data);
diff --git a/libgphoto2/gphoto2-file.c b/libgphoto2/gphoto2-file.c
index 5eaf3a180..3dad2cbe8 100644
--- a/libgphoto2/gphoto2-file.c
+++ b/libgphoto2/gphoto2-file.c
@@ -209,11 +209,7 @@ gp_file_append (CameraFile *file, const char *data,
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
- if (!file->data)
- C_MEM (file->data = malloc (sizeof(char) * (size)));
- else {
- C_MEM (file->data = realloc (file->data, sizeof (char) * (file->size + size)));
- }
+ C_MEM (file->data = realloc (file->data, sizeof (char) * (file->size + size)));
memcpy (&file->data[file->size], data, size);
file->size += size;
break;
diff --git a/libgphoto2/gphoto2-widget.c b/libgphoto2/gphoto2-widget.c
index d90752c36..d354950b9 100644
--- a/libgphoto2/gphoto2-widget.c
+++ b/libgphoto2/gphoto2-widget.c
@@ -471,7 +471,6 @@ gp_widget_get_value (CameraWidget *widget, void *value)
int
gp_widget_append (CameraWidget *widget, CameraWidget *child)
{
- CameraWidget **newlist;
CHECK_NULL (widget && child);
/* Return if they can't have any children */
@@ -479,11 +478,7 @@ gp_widget_append (CameraWidget *widget, CameraWidget *child)
(widget->type != GP_WIDGET_SECTION))
return (GP_ERROR_BAD_PARAMETERS);
- if (widget->children_count)
- C_MEM (newlist = realloc(widget->children,sizeof(CameraWidget*)*(widget->children_count+1)));
- else
- C_MEM (newlist = malloc(sizeof(CameraWidget*)));
- widget->children = newlist;
+ C_MEM (widget->children = realloc(widget->children, sizeof(CameraWidget*)*(widget->children_count+1)));
widget->children[widget->children_count] = child;
widget->children_count += 1;
child->parent = widget;
@@ -504,7 +499,6 @@ int
gp_widget_prepend (CameraWidget *widget, CameraWidget *child)
{
int x;
- CameraWidget** newlist;
CHECK_NULL (widget && child);
@@ -513,11 +507,7 @@ gp_widget_prepend (CameraWidget *widget, CameraWidget *child)
(widget->type != GP_WIDGET_SECTION))
return (GP_ERROR_BAD_PARAMETERS);
- if (widget->children_count)
- C_MEM (newlist = realloc(widget->children,sizeof(CameraWidget*)*(widget->children_count+1)));
- else
- C_MEM (newlist = malloc(sizeof(CameraWidget*)));
- widget->children = newlist;
+ C_MEM (widget->children = realloc(widget->children, sizeof(CameraWidget*)*(widget->children_count+1)));
/* Shift down 1 */
for (x = widget->children_count; x > 0; x--)
@@ -778,19 +768,12 @@ gp_widget_get_range (CameraWidget *range, float *min, float *max,
int
gp_widget_add_choice (CameraWidget *widget, const char *choice)
{
- char **choices;
CHECK_NULL (widget && choice);
if ((widget->type != GP_WIDGET_RADIO) &&
(widget->type != GP_WIDGET_MENU))
return (GP_ERROR_BAD_PARAMETERS);
- if (widget->choice_count) {
- C_MEM (choices = realloc (widget->choice, sizeof(char*)*(widget->choice_count+1)));
- } else {
- C_MEM (choices = malloc (sizeof(char*)));
- }
-
- widget->choice = choices;
+ C_MEM (widget->choice = realloc (widget->choice, sizeof(char*)*(widget->choice_count+1)));
widget->choice[widget->choice_count] = strdup(choice);
widget->choice_count += 1;
return (GP_OK);