changeset 677:94be6289538b

sexpr: make sexpr_list_to_array's arg & return type LP64-friendly Since they are supposed to hold a count of items held in memory, we must use size_t and ssize_t types instead of abusing int. On ILP32 systems, it doesn't matter but on LP64 we run the risk of overflowing the integer. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sun, 24 Feb 2019 13:11:11 -0500
parents 2730e7a80abd
children 5c64f103bcef
files include/jeffpc/sexpr.h sexpr.c
diffstat 2 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/include/jeffpc/sexpr.h	Sun Feb 24 10:36:28 2019 -0500
+++ b/include/jeffpc/sexpr.h	Sun Feb 24 13:11:11 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -38,7 +38,8 @@
 extern int sexpr_dump_file(FILE *out, struct val *lv, bool raw);
 extern struct val *sexpr_array_to_list(struct val **vals, size_t nvals);
 extern struct val *sexpr_args_to_list(size_t nvals, ...);
-extern int sexpr_list_to_array(struct val *list, struct val **array, int alen);
+extern ssize_t sexpr_list_to_array(struct val *list, struct val **array,
+				   size_t alen);
 extern struct val *sexpr_list_to_val_array(struct val *list);
 
 static inline struct val *sexpr_parse_str(struct str *str)
--- a/sexpr.c	Sun Feb 24 10:36:28 2019 -0500
+++ b/sexpr.c	Sun Feb 24 13:11:11 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2015-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -105,10 +105,10 @@
  * We fill in the passed in array with at most alen elements.  The number of
  * filled in elements is returned to the caller.
  */
-int sexpr_list_to_array(struct val *list, struct val **array, int alen)
+ssize_t sexpr_list_to_array(struct val *list, struct val **array, size_t alen)
 {
 	struct val *tmp;
-	int nvals = 0;
+	size_t nvals = 0;
 
 	for (tmp = list;
 	     !sexpr_is_null(tmp) && (alen > nvals);