Avoid use of gets() in DOE-ProxyApps-C/Pathfinder
gets() has been removed from C11 and on FreeBSD 13 libc no longer provides
it by default. Use fgets() instead.
Reviewed By: arichardson
Differential Revision: https://reviews.llvm.org/D89556
(cherry picked from commit ad49cd738e93f77b86bae2ac6a127ed886427d25)
diff --git a/MultiSource/Benchmarks/DOE-ProxyApps-C/Pathfinder/main.c b/MultiSource/Benchmarks/DOE-ProxyApps-C/Pathfinder/main.c
index cfa741a..fb35298 100644
--- a/MultiSource/Benchmarks/DOE-ProxyApps-C/Pathfinder/main.c
+++ b/MultiSource/Benchmarks/DOE-ProxyApps-C/Pathfinder/main.c
@@ -276,6 +276,20 @@
printf ("\n\nSearches complete.\n");
}
+void mygets(char *str, size_t n)
+{
+ size_t len;
+
+ if ( fgets(str, n, stdin) == NULL )
+ {
+ printf("Error: No input provided.\n\n\t---Exiting---");
+ exit(0);
+ }
+
+ len = strlen(str);
+ if ( len > 0 && str[len - 1] == '\n' )
+ str[len - 1] = '\0';
+}
void runInteractively(char *fileName, Configuration *config)
{
@@ -299,7 +313,7 @@
do {
printf("\nPlease insert a node label for this signature (\"\" to complete, \"bail\" to exit):\n");
- gets(stringBuffer);
+ mygets(stringBuffer, sizeof stringBuffer);
if ( strcmp (stringBuffer, "bail") == 0 )
exit(1);