Skip to content

Commit

Permalink
[BUG FIX] fix examples segment fault (nacos-group#148)
Browse files Browse the repository at this point in the history
1. we should clear buffer before we use getchar
  • Loading branch information
CedarBetty committed Jan 22, 2025
1 parent 2b4104d commit 8156c62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/listenToKeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ int main() {
getchar();
cout << "remove listener" << endl;
n->removeListener("dqid", NULLSTR, theListener);//Cancel listening
int c;
while ((c = getchar()) != '\n' && c != EOF);
getchar();

return 0;
Expand Down
3 changes: 3 additions & 0 deletions examples/subscribeServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ int main() {
n->registerInstance("ss", "127.0.0.1", 33);
n->registerInstance("ss", "127.0.0.1", 34);
cout << "Press any key to deregister services" << endl;
int c;
while ((c = getchar()) != '\n' && c != EOF);
getchar();

n->deregisterInstance("ss", "127.0.0.1", 33);
n->deregisterInstance("ss", "127.0.0.1", 34);
cout << "All instances Unregistered, press any key to finish testing" << endl;
while ((c = getchar()) != '\n' && c != EOF);
getchar();

return 0;
Expand Down

0 comments on commit 8156c62

Please sign in to comment.