Welcome! Log In Create A New Profile

Advanced

[njs] Fixed returned value for Buffer.prototype.write* functions.

Alexander Borisov
October 19, 2020 09:14AM
details: https://hg.nginx.org/njs/rev/4106bf95d343
branches:
changeset: 1540:4106bf95d343
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Mon Oct 19 15:51:37 2020 +0300
description:
Fixed returned value for Buffer.prototype.write* functions.

All Buffer.prototype.write* functions must return offset plus
the number of bytes written.

The issue was introduced in 27bb9caf186c.

diffstat:

src/njs_buffer.c | 2 +-
src/test/njs_unit_test.c | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r a82f123409b7 -r 4106bf95d343 src/njs_buffer.c
--- a/src/njs_buffer.c Tue Oct 13 15:44:33 2020 +0300
+++ b/src/njs_buffer.c Mon Oct 19 15:51:37 2020 +0300
@@ -1331,7 +1331,7 @@ njs_buffer_prototype_write_int(njs_vm_t
break;
}

- njs_set_undefined(&vm->retval);
+ njs_set_number(&vm->retval, index + size);

return NJS_OK;
}
diff -r a82f123409b7 -r 4106bf95d343 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Oct 13 15:44:33 2020 +0300
+++ b/src/test/njs_unit_test.c Mon Oct 19 15:51:37 2020 +0300
@@ -19191,7 +19191,11 @@ static njs_unit_test_t njs_test[] =
" if (size > 1) { rmethod += endianness; wmethod += endianness; };"
" var v = 0x7abbccddeeff & (size * 8 - 1);"
""
- " buf[wgmethod](v, offset, size);"
+ " var ret = buf[wgmethod](v, offset, size);"
+ " if(ret !== offset + size) {"
+ " throw Error(`${wgmethod} returned ${ret}, need ${offset + size}`);"
+ " }"
+ ""
" var gv = buf[rgmethod](offset, size);"
""
" buf.fill(0);"
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed returned value for Buffer.prototype.write* functions.

Alexander Borisov 110 October 19, 2020 09:14AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 85
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready