[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 118/324: netstruct: Fix field lookup and offset calculat
From: |
gnunet |
Subject: |
[gnunet-scheme] 118/324: netstruct: Fix field lookup and offset calculation. |
Date: |
Tue, 21 Sep 2021 13:22:38 +0200 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit 22153b9827f87660fd0417004099737a930b623a
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sat May 29 19:09:43 2021 +0200
netstruct: Fix field lookup and offset calculation.
The first issue is a wrong comparison: (> i vlen)
instead of (< i vlen). A second issue is an ambigious
variable name, where the wrong variable is used.
A third issue is forgetting to actually return the
field during field lookup.
* tests/netstruct.scm: Test it.
* gnu/gnunet/netstruct/procedural.scm (vtable/struct)
[offsetof]: Correct bounds check and disambiguate variable names.
[part]: Actually return the field.
---
Makefile.am | 3 ++-
gnu/gnunet/netstruct/procedural.scm | 13 +++++++------
tests/netstruct.scm | 31 +++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 51273bf..8b15711 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -105,7 +105,8 @@ SCM_TESTS = \
tests/config-parser.scm \
tests/config-value-parser.scm \
tests/config-expander.scm \
- tests/config-db.scm
+ tests/config-db.scm \
+ tests/netstruct.scm
SCM_TESTS_ENVIRONMENT = \
GUILE_AUTO_COMPILE=0 \
diff --git a/gnu/gnunet/netstruct/procedural.scm
b/gnu/gnunet/netstruct/procedural.scm
index 2a38db7..0db2d6d 100644
--- a/gnu/gnunet/netstruct/procedural.scm
+++ b/gnu/gnunet/netstruct/procedural.scm
@@ -284,19 +284,20 @@ structure @var{ns} in the bytevector slice @var{ns}."
(let* ((vec (%netstruct-fields ns))
(vlen (vector-length vec)))
(let loop ((i 0) (off 0))
- (unless (> i vlen)
+ (unless (< i vlen)
(no-such-field 'offsetof))
- (let* ((field (vector-ref vec i))
- (fsize (%size (field-type field))))
- (if (eq? (field-name field) field)
+ (let* ((field-found (vector-ref vec i))
+ (field-size (%size (field-type field-found))))
+ (if (eq? (field-name field-found) field)
off
(loop (+ i 1)
- (+ off fsize)))))))
+ (+ off field-size)))))))
(define (part ns field)
(let* ((vec (%netstruct-fields ns)))
(or (vector-any (lambda (f)
- (eq? (field-name f) field))
+ (and (eq? (field-name f) field)
+ (field-type f)))
vec)
(no-such-field 'part))))
(make-netstruct-vtable
diff --git a/tests/netstruct.scm b/tests/netstruct.scm
new file mode 100644
index 0000000..5a2bca8
--- /dev/null
+++ b/tests/netstruct.scm
@@ -0,0 +1,31 @@
+;; This file is part of scheme-GNUnet.
+;; Copyright (C) 2021 Maxime Devos
+;;
+;; scheme-GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; scheme-GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL3.0-or-later
+(import (srfi srfi-26)
+ (gnu gnunet netstruct procedural))
+
+(test-begin "netstruct procedural")
+
+(define struct/a
+ (make-netstructure
+ (vector (make-field 'field u8))))
+
+(test-eqv "first field, offset (struct)"
+ 0
+ (offsetof struct/a '(field)))
+
+(test-end "netstruct procedural")
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 123/324: netstruct: Select a part of the slice before trying to read., (continued)
- [gnunet-scheme] 123/324: netstruct: Select a part of the slice before trying to read., gnunet, 2021/09/21
- [gnunet-scheme] 124/324: netstruct: Use the correct size for bounds checking in 'select'., gnunet, 2021/09/21
- [gnunet-scheme] 130/324: mq: New module, replacing message-io., gnunet, 2021/09/21
- [gnunet-scheme] 132/324: mq: Do not hardcode suspicious queue length., gnunet, 2021/09/21
- [gnunet-scheme] 133/324: mq: Pluralise ‘message-queue-handler’., gnunet, 2021/09/21
- [gnunet-scheme] 137/324: mq: Make %suspicious-length a sort-of exported parameter., gnunet, 2021/09/21
- [gnunet-scheme] 139/324: mq: Make accessors of &overly-full-queue-warnings predictably named., gnunet, 2021/09/21
- [gnunet-scheme] 141/324: mq: Return the envelope after enqueueing and add more tests., gnunet, 2021/09/21
- [gnunet-scheme] 147/324: Merge branch 'master' into proper-mq, gnunet, 2021/09/21
- [gnunet-scheme] 97/324: utils: bv-slice: Define a record printer., gnunet, 2021/09/21
- [gnunet-scheme] 118/324: netstruct: Fix field lookup and offset calculation.,
gnunet <=
- [gnunet-scheme] 140/324: mq: Export &overly-full-queue-warning and friends., gnunet, 2021/09/21
- [gnunet-scheme] 144/324: mq: Test message cancellation., gnunet, 2021/09/21
- [gnunet-scheme] 145/324: mq: envelope: Correct spelling in comments and docstrings., gnunet, 2021/09/21
- [gnunet-scheme] 87/324: mq: define message queue module, gnunet, 2021/09/21
- [gnunet-scheme] 96/324: doc: Fix typo in README.org., gnunet, 2021/09/21
- [gnunet-scheme] 102/324: tests: config-parser: Don't generate inexact numbers., gnunet, 2021/09/21
- [gnunet-scheme] 116/324: utils: hat-let: Fix inline procedure definitions., gnunet, 2021/09/21
- [gnunet-scheme] 117/324: mq: Define envelope data type, again., gnunet, 2021/09/21
- [gnunet-scheme] 126/324: netstruct: Verify there is a setter (not a reader) in set%!., gnunet, 2021/09/21
- [gnunet-scheme] 128/324: netstruct: Raise &unwritable, not an &unreadable, in set%!., gnunet, 2021/09/21