aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/utils.c
diff options
context:
space:
mode:
authorRichard Carlsson <[email protected]>2015-12-03 14:33:53 +0100
committerSverker Eriksson <[email protected]>2016-02-08 16:11:56 +0100
commit14680fcc3fb9d0357fe33a94525d08896afed1c5 (patch)
tree40b1891cdbe478154d62262616494dbc27eabcf1 /erts/emulator/beam/utils.c
parentacc4ac9f421e064bc0e573a9d5ecd26afe7cb8d6 (diff)
downloadotp-14680fcc3fb9d0357fe33a94525d08896afed1c5.tar.gz
otp-14680fcc3fb9d0357fe33a94525d08896afed1c5.tar.bz2
otp-14680fcc3fb9d0357fe33a94525d08896afed1c5.zip
erts: Use Sint instead of int for list lengths
This avoids potential integer arithmetic overflow for very large lists.
Diffstat (limited to 'erts/emulator/beam/utils.c')
-rw-r--r--erts/emulator/beam/utils.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c
index ef851d840d..35dfee49cd 100644
--- a/erts/emulator/beam/utils.c
+++ b/erts/emulator/beam/utils.c
@@ -317,10 +317,10 @@ erl_grow_equeue(ErtsEQueue* q, Eterm* default_equeue)
* Calculate length of a list.
* Returns -1 if not a proper list (i.e. not terminated with NIL)
*/
-int
+Sint
erts_list_length(Eterm list)
{
- int i = 0;
+ Sint i = 0;
while(is_list(list)) {
i++;
@@ -3930,11 +3930,11 @@ void bin_write(int to, void *to_arg, byte* buf, size_t sz)
/* Fill buf with the contents of bytelist list
return number of chars in list or -1 for error */
-int
-intlist_to_buf(Eterm list, char *buf, int len)
+Sint
+intlist_to_buf(Eterm list, char *buf, Sint len)
{
Eterm* listptr;
- int sz = 0;
+ Sint sz = 0;
if (is_nil(list))
return 0;
@@ -4481,11 +4481,12 @@ int erts_iolist_size(Eterm obj, ErlDrvSizeT* sizep)
return iolist_size(0, NULL, obj, sizep);
}
-/* return 0 if item is not a non-empty flat list of bytes */
-int
+/* return 0 if item is not a non-empty flat list of bytes
+ otherwise return the nonzero length of the list */
+Sint
is_string(Eterm list)
{
- int len = 0;
+ Sint len = 0;
while(is_list(list)) {
Eterm* consp = list_val(list);