1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-16 16:50:21 +02:00

Fix list validation of *list->bytevector procedures.

Fixes <https://bugs.gnu.org/32938>.
Reported by Josh Datko <jbd@cryptotronix.com>.

* libguile/validate.h (SCM_VALIDATE_LIST_COPYLEN)
(SCM_VALIDATE_NONEMPTYLIST_COPYLEN): Use '!=' instead of '>=' to
validate the result of 'scm_ilength' after it has been stored in
the user variable 'cvar'.
* test-suite/tests/bytevectors.test: Add tests.  Use '#:use-module'
instead of ':use-module' in 'define-module' form.
This commit is contained in:
Mark H Weaver 2018-10-14 02:22:22 -04:00 committed by Andy Wingo
parent 0c0a658c56
commit 5dcad70d99
2 changed files with 39 additions and 8 deletions

View file

@ -1,7 +1,7 @@
#ifndef SCM_LIST_H
#define SCM_LIST_H
/* Copyright 1995-1997,2000-2001,2003-2006,2008-2009,2018
/* Copyright 1995-1997,2000-2001,2003-2006,2008-2009,2018-2019
Free Software Foundation, Inc.
This file is part of Guile.
@ -88,16 +88,20 @@ SCM_API SCM scm_copy_tree (SCM obj);
SCM_ASSERT (scm_ilength (lst) > 0, lst, pos, FUNC_NAME); \
} while (0)
/* Note: we use (cvar != -1) instead of (cvar >= 0) below
in case 'cvar' is of unsigned type. */
#define SCM_VALIDATE_LIST_COPYLEN(pos, lst, cvar) \
do { \
cvar = scm_ilength (lst); \
SCM_ASSERT (cvar >= 0, lst, pos, FUNC_NAME); \
SCM_ASSERT (cvar != -1, lst, pos, FUNC_NAME); \
} while (0)
/* Note: we use (cvar != -1) instead of (cvar >= 0) below
in case 'cvar' is of unsigned type. */
#define SCM_VALIDATE_NONEMPTYLIST_COPYLEN(pos, lst, cvar) \
do { \
cvar = scm_ilength (lst); \
SCM_ASSERT (cvar >= 1, lst, pos, FUNC_NAME); \
SCM_ASSERT (cvar != -1, lst, pos, FUNC_NAME); \
} while (0)