From ae49fce8e19f7544c463cfbff58794f35f44c493 Mon Sep 17 00:00:00 2001
From: WangFengTu <wangfengtu@huawei.com>
Date: Thu, 9 Jun 2022 16:17:52 +0800
Subject: [PATCH 16/30] do not fail if pw is not NULL

Signed-off-by: WangFengTu <wangfengtu@huawei.com>
---
 src/utils/cutils/utils_pwgr.c           | 7 +------
 test/cutils/utils_pwgr/utils_pwgr_ut.cc | 5 ++---
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/utils/cutils/utils_pwgr.c b/src/utils/cutils/utils_pwgr.c
index 01490863..6b83f787 100644
--- a/src/utils/cutils/utils_pwgr.c
+++ b/src/utils/cutils/utils_pwgr.c
@@ -212,11 +212,6 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu
         return -1;
     }
 
-    if (*result != NULL) {
-        ERROR("Result shall point to null to start.");
-        return -1;
-    }
-
     buff_end = buffer + buflen - 1;
     flockfile(stream);
 
@@ -337,4 +332,4 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf
 out:
     funlockfile(stream);
     return ret;
-}
\ No newline at end of file
+}
diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
index 00a32e05..bf9c9f06 100644
--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc
+++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
@@ -44,7 +44,7 @@ TEST(utils_pwgr, test_getpwent_r)
     ASSERT_EQ(util_getpwent_r(NULL, &pw, buf, sizeof(buf), &ppw), -1);
     ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 0, &ppw), -1);
     ASSERT_EQ(util_getpwent_r(f_pw, &pw, invalid_buf, 1, &ppw), -1);
-    ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), -1);
+    ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), 0);
     ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), NULL), -1);
 
     while (!feof(f_pw)) {
@@ -65,7 +65,6 @@ TEST(utils_pwgr, test_getpwent_r)
         ASSERT_STREQ(pw.pw_dir, std::get<5>(elem).c_str());
         ASSERT_STREQ(pw.pw_shell, std::get<6>(elem).c_str());
         EXPECT_TRUE(ppw == &pw);
-        ppw = nullptr;
         pw = {0};
     }
 
@@ -134,4 +133,4 @@ TEST(utils_pwgr, test_getgrent_r)
     }
 
     fclose(f_gr);
-}
\ No newline at end of file
+}
-- 
2.32.1 (Apple Git-133)

