summaryrefslogtreecommitdiffhomepage
path: root/test/test_java_application.py
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@nginx.com>2022-10-29 23:23:06 +0200
committerAlejandro Colomar <alx@kernel.org>2022-11-12 20:22:07 +0100
commit317a217bf8fa6c31c1b48193941a50ef64c155ab (patch)
treef11bea88873d44b81e2d158e75a34e043d40205a /test/test_java_application.py
parent3bbb13b7d2275adbeef528cebf8bd9e8a5a07696 (diff)
downloadunit-317a217bf8fa6c31c1b48193941a50ef64c155ab.tar.gz
unit-317a217bf8fa6c31c1b48193941a50ef64c155ab.tar.bz2
Using nxt_nitems() instead of sizeof() for strings (arrays).
sizeof() should never be used to get the size of an array. It is very unsafe, since arrays easily decay to pointers, and sizeof() applied to a pointer gives false results that compile and produce silent bugs. It's better to use nxt_items(), which implements sizeof() division, which recent compilers warn when used with pointers. This change would have avoided a bug that we almost introduced recently by using: nxt_str_set(&port, (r->tls ? "https://" : "http://")); which in the macro expansion runs: (&port)->length = nxt_length((r->tls ? : "https://" : "http://")); which evaluates to: port.length = sizeof(r->tls ? "https://" : "http://") - 1; which evaluates to: port.length = 8 - 1; Of course, we didn't want a compile-time-constant 8 there, but rather the length of the string. Link: <https://stackoverflow.com/a/57537491> Cc: Andrew Clayton <a.clayton@nginx.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to 'test/test_java_application.py')
0 files changed, 0 insertions, 0 deletions