public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH ncns v1 0/2] ncns fixes
@ 2022-08-17  1:09 Ammar Faizi
  2022-08-17  1:09 ` [PATCH ncns v1 1/2] chnet: node: Only take the pointer of buffer when available Ammar Faizi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ammar Faizi @ 2022-08-17  1:09 UTC (permalink / raw)
  To: Alviro Iskandar Setiawan; +Cc: Ammar Faizi, GNU/Weeb Mailing List

Hi Al,

Two fixes this time:

1) Only take the pointer of buffer when available.

The call to `ch->ch_.read_buf()` may be undefined behavior if the
buffer hasn't been initialized. Don't touch this buffer and return
null if it's not guaranteed to be initialized.

2) Fix unused variable warning.

Fix this:

  ../chnet/chnet_node.cc: In function ‘void CHN_RingWaitCQE(const Napi::CallbackInfo&)’:
  ../chnet/chnet_node.cc:146:19: warning: variable ‘env’ set but not used [-Wunused-but-set-variable]
    146 |         Napi::Env env = info.Env();
        |                   ^~~

Signed-off-by: Ammar Faizi <[email protected]>
---

Ammar Faizi (2):
  chnet: node: Only take the pointer of buffer when available
  chnet: node: Fix unused variable warning

 chnet/chnet_node.cc | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)


base-commit: 2b40ff58ef9007013ec741d2d599869e4c0b46f2
-- 
Ammar Faizi


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH ncns v1 1/2] chnet: node: Only take the pointer of buffer when available
  2022-08-17  1:09 [PATCH ncns v1 0/2] ncns fixes Ammar Faizi
@ 2022-08-17  1:09 ` Ammar Faizi
  2022-08-17  1:09 ` [PATCH ncns v1 2/2] chnet: node: Fix unused variable warning Ammar Faizi
  2022-08-17  1:14 ` [PATCH ncns v1 0/2] ncns fixes Alviro Iskandar Setiawan
  2 siblings, 0 replies; 4+ messages in thread
From: Ammar Faizi @ 2022-08-17  1:09 UTC (permalink / raw)
  To: Alviro Iskandar Setiawan; +Cc: Ammar Faizi, GNU/Weeb Mailing List

The call to `ch->ch_.read_buf()` may be undefined behavior if the
buffer hasn't been initialized. Don't touch this buffer and return
null if it's not guaranteed to be initialized.

Signed-off-by: Ammar Faizi <[email protected]>
---
 chnet/chnet_node.cc | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/chnet/chnet_node.cc b/chnet/chnet_node.cc
index 1491fd8..c89a745 100644
--- a/chnet/chnet_node.cc
+++ b/chnet/chnet_node.cc
@@ -267,20 +267,18 @@ static void CHN_NetSetURL(const Napi::CallbackInfo &info)
 	ch->ch_.SetURL(url.c_str());
 }
 
-static Napi::String CHN_NetReadBuf(const Napi::CallbackInfo &info)
+static Napi::Value CHN_NetReadBuf(const Napi::CallbackInfo &info)
 {
 	Napi::Env env = info.Env();
-	const char *buf;
 	CHNetNode *ch;
 	int ret;
 
 	ch = (CHNetNode *)info.Data();
-	buf = ch->ch_.read_buf();
 	ret = ch->ch_.read_ret();
 	if (ret > 0)
-		return Napi::String::New(env, buf, (size_t)ret);
+		return Napi::String::New(env, ch->ch_.read_buf(), (size_t)ret);
 
-	return Napi::String::New(env, "");
+	return env.Null();
 }
 
 static Napi::Number CHN_NetReadRet(const Napi::CallbackInfo &info)
-- 
Ammar Faizi


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH ncns v1 2/2] chnet: node: Fix unused variable warning
  2022-08-17  1:09 [PATCH ncns v1 0/2] ncns fixes Ammar Faizi
  2022-08-17  1:09 ` [PATCH ncns v1 1/2] chnet: node: Only take the pointer of buffer when available Ammar Faizi
@ 2022-08-17  1:09 ` Ammar Faizi
  2022-08-17  1:14 ` [PATCH ncns v1 0/2] ncns fixes Alviro Iskandar Setiawan
  2 siblings, 0 replies; 4+ messages in thread
From: Ammar Faizi @ 2022-08-17  1:09 UTC (permalink / raw)
  To: Alviro Iskandar Setiawan; +Cc: Ammar Faizi, GNU/Weeb Mailing List

Fix this:

  ../chnet/chnet_node.cc: In function ‘void CHN_RingWaitCQE(const Napi::CallbackInfo&)’:
  ../chnet/chnet_node.cc:146:19: warning: variable ‘env’ set but not used [-Wunused-but-set-variable]
    146 |         Napi::Env env = info.Env();
        |                   ^~~

Fixes: 4fc27d45cfbb5a19a499ca4398b522038cbd8e42 ("chnet_node: Fully integrate chnet ring with NodeJS")
Signed-off-by: Ammar Faizi <[email protected]>
---
 chnet/chnet_node.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/chnet/chnet_node.cc b/chnet/chnet_node.cc
index c89a745..06f624e 100644
--- a/chnet/chnet_node.cc
+++ b/chnet/chnet_node.cc
@@ -143,7 +143,6 @@ static Napi::Value CHN_RingSubmitSQE(const Napi::CallbackInfo &info)
 
 static void CHN_RingWaitCQE(const Napi::CallbackInfo &info)
 {
-	Napi::Env env = info.Env();
 	uint32_t to_wait;
 	CNRingCtx *ring;
 
-- 
Ammar Faizi


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH ncns v1 0/2] ncns fixes
  2022-08-17  1:09 [PATCH ncns v1 0/2] ncns fixes Ammar Faizi
  2022-08-17  1:09 ` [PATCH ncns v1 1/2] chnet: node: Only take the pointer of buffer when available Ammar Faizi
  2022-08-17  1:09 ` [PATCH ncns v1 2/2] chnet: node: Fix unused variable warning Ammar Faizi
@ 2022-08-17  1:14 ` Alviro Iskandar Setiawan
  2 siblings, 0 replies; 4+ messages in thread
From: Alviro Iskandar Setiawan @ 2022-08-17  1:14 UTC (permalink / raw)
  To: Ammar Faizi; +Cc: GNU/Weeb Mailing List

On Wed, Aug 17, 2022 at 8:09 AM Ammar Faizi wrote:
> Hi Al,
>
> Two fixes this time:

applied

tq

-- Viro

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-17  1:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-17  1:09 [PATCH ncns v1 0/2] ncns fixes Ammar Faizi
2022-08-17  1:09 ` [PATCH ncns v1 1/2] chnet: node: Only take the pointer of buffer when available Ammar Faizi
2022-08-17  1:09 ` [PATCH ncns v1 2/2] chnet: node: Fix unused variable warning Ammar Faizi
2022-08-17  1:14 ` [PATCH ncns v1 0/2] ncns fixes Alviro Iskandar Setiawan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox