summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2018-11-06 17:14:20 -0500
committerJason Woodward2018-11-06 17:14:20 -0500
commit64fe69d3d35de543f48f5c31cbf22710e6fade63 (patch)
treea3c7b701b31d8fdd17ef436c0d7b17bbef5098d1
parent9c0d594aa534f229b3e9b61ae5d8c8599af9d44f (diff)
downloadslapt-get-64fe69d3d35de543f48f5c31cbf22710e6fade63.tar.gz
tweak foreach macros
-rw-r--r--src/common.h2
-rw-r--r--src/configuration.h2
-rw-r--r--src/package.h6
-rw-r--r--src/transaction.h2
4 files changed, 6 insertions, 6 deletions
diff --git a/src/common.h b/src/common.h
index 71d9857..e6fd453 100644
--- a/src/common.h
+++ b/src/common.h
@@ -71,7 +71,7 @@ typedef struct {
char **items;
uint32_t count;
} slapt_list_t;
-#define slapt_list_t_foreach(item, list) char *item; for (uint32_t item##_counter = 0; item = list->items[item##_counter], item##_counter < list->count; item##_counter++)
+#define slapt_list_t_foreach(item, list) char *item; for (uint32_t item##_counter = 0; (item##_counter < list->count) && (item = list->items[item##_counter]); item##_counter++)
FILE *slapt_open_file(const char *file_name, const char *mode);
diff --git a/src/configuration.h b/src/configuration.h
index 7eb548c..ceb0aad 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -33,7 +33,7 @@ typedef struct {
slapt_source_t **src;
uint32_t count;
} slapt_source_list_t;
-#define slapt_source_list_t_foreach(item, list) slapt_source_t *item; for (uint32_t item##_counter = 0; item = list->src[item##_counter], item##_counter < list->count; item##_counter++)
+#define slapt_source_list_t_foreach(item, list) slapt_source_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->count) && (item = list->src[item##_counter]); item##_counter++)
typedef struct {
char working_dir[SLAPT_WORKINGDIR_TOKEN_LEN];
diff --git a/src/package.h b/src/package.h
index 70b6327..96e27f9 100644
--- a/src/package.h
+++ b/src/package.h
@@ -75,7 +75,7 @@ typedef struct {
bool free_pkgs;
bool ordered;
} slapt_pkg_list_t;
-#define slapt_pkg_list_t_foreach(item, list) slapt_pkg_info_t *item; for (uint32_t item##_counter = 0; item = list->pkgs[item##_counter], item##_counter < list->pkg_count; item##_counter++)
+#define slapt_pkg_list_t_foreach(item, list) slapt_pkg_info_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->pkg_count) && (item = list->pkgs[item##_counter]); item##_counter++)
typedef struct {
slapt_pkg_info_t *installed;
@@ -88,7 +88,7 @@ typedef struct {
uint32_t pkg_count;
uint32_t reinstall_count;
} slapt_pkg_upgrade_list_t;
-#define slapt_pkg_upgrade_list_t_foreach(item, list) slapt_pkg_upgrade_t *item; for (uint32_t item##_counter = 0; item = list->pkgs[item##_counter], item##_counter < list->pkg_count; item##_counter++)
+#define slapt_pkg_upgrade_list_t_foreach(item, list) slapt_pkg_upgrade_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->pkg_count) && (item = list->pkgs[item##_counter]); item##_counter++)
typedef struct {
char *pkg;
@@ -99,7 +99,7 @@ typedef struct {
slapt_pkg_err_t **errs;
uint32_t err_count;
} slapt_pkg_err_list_t;
-#define slapt_pkg_err_list_t_foreach(item, list) slapt_pkg_err_t *item; for (uint32_t item##_counter = 0; item = list->errs[item##_counter], item##_counter < list->err_count; item##_counter++)
+#define slapt_pkg_err_list_t_foreach(item, list) slapt_pkg_err_t *item; for (uint32_t item##_counter = 0; (item##_counter < list->err_count) && (item = list->errs[item##_counter]); item##_counter++)
/* returns an empty package structure */
slapt_pkg_info_t *slapt_init_pkg(void);
diff --git a/src/transaction.h b/src/transaction.h
index 7765592..1723cbd 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -34,7 +34,7 @@ typedef struct {
slapt_queue_i **pkgs;
uint32_t count;
} slapt_queue_t;
-#define slapt_queue_t_foreach(item, list) slapt_queue_i *item; for (uint32_t item##_counter = 0; item = list->pkgs[item##_counter], item##_counter < list->count; item##_counter++)
+#define slapt_queue_t_foreach(item, list) slapt_queue_i *item; for (uint32_t item##_counter = 0; (item##_counter < list->count) && (item = list->pkgs[item##_counter]); item##_counter++)
typedef struct {
slapt_pkg_list_t *install_pkgs;