delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2011/07/02/14:44:18

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX1+padEhsn2pKffCzaFlbXMPrXmTTqFIn/J877cmud
3IqEZCM+Te+CSf
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: Re: [patch] kill gets() usage in stubedit.c, use fgets()
Date: Sat, 2 Jul 2011 20:32:10 +0200
User-Agent: KMail/1.9.10
References: <BANLkTimnFhfjYM=HbSmv5v7KdCkKfVLrgQ AT mail DOT gmail DOT com> <201107021926 DOT 48563 DOT juan DOT guerrero AT gmx DOT de> <BANLkTi=f2bhVUio9R4Sb60LHB0Wb5-79YQ AT mail DOT gmail DOT com>
In-Reply-To: <BANLkTi=f2bhVUio9R4Sb60LHB0Wb5-79YQ@mail.gmail.com>
MIME-Version: 1.0
Message-Id: <201107022032.10137.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

Am Samstag, 2. Juli 2011 schrieb Ozkan Sezer:
[snip]
> Quick scanning reveals:
> 
> src/utils/djtar/djtar.c: line #208:  Missed this because I never use
> it, not needed in cross-tools
> 
> src/libc/dos/dir/fnsplit.c::main() line #119 (but that's only  TEST code,
> not compiled into lib.)

Yes, I found the same.  The proposed changes seem ok to me.  If no one oposses
I will commit the patch below.

Regards,
Juan M. Guerrero



	* src/stub/stubedit.c:  Use fgets instead of gets.
	From Ozkan Sezer <sezeroz AT gmail DOT com>

	* src/utils/djtar/djtar.c:  Use fgets instead of gets.
	From Ozkan Sezer <sezeroz AT gmail DOT com>


diff -aprNU3 djgpp.orig/src/stub/stubedit.c djgpp/src/stub/stubedit.c
--- djgpp.orig/src/stub/stubedit.c	2003-01-05 17:59:26 +0000
+++ djgpp/src/stub/stubedit.c	2011-07-02 20:20:40 +0000
@@ -87,9 +87,20 @@ void store_info(char *filename)
 char *pose_question(char *question, char *default_answer)
 {
   static char response[200];
+  char *ptr;
   printf("%s ? [%s] ", question, default_answer);
   fflush(stdout);
-  gets(response);
+  ptr = fgets(response, sizeof(response), stdin);
+  if (!ptr)
+    return 0;
+  for (; *ptr; ++ptr)
+  {
+    if (*ptr == '\n')
+    {
+      *ptr = '\0';
+      break;
+    }
+  }
   if (response[0] == '\0')
     return 0;
   return response;
diff -aprNU3 djgpp.orig/src/utils/djtar/djtar.c djgpp/src/utils/djtar/djtar.c
--- djgpp.orig/src/utils/djtar/djtar.c	2011-02-26 19:52:06 +0000
+++ djgpp/src/utils/djtar/djtar.c	2011-07-02 20:27:00 +0000
@@ -205,12 +205,21 @@ change(char *fname, const char *problem,
   fprintf(log_out, "  %s %s\n  new name : ", problem, fname);
   fflush(log_out);
   new[0] = '\0';
-  if (!gets(new))
+  pos = fgets(new, sizeof(new), stdin);
+  if (!pos)
     Fatal("EOF while reading stdin");
+  for (; *pos; ++pos)
+  {
+    if (*pos == '\n')
+    {
+      *pos = '\0';
+      break;
+    }
+  }
 
-  if ((strcmp(new, "") == 0) && (isadir == 2))
+  if ((new[0] == '\0') && (isadir == 2))
     return 0;
-  if (isadir) isadir=1;
+  if (isadir) isadir = 1;
   ch = (CHANGE *)xmalloc(sizeof(CHANGE));
   ch->next = change_root;
   change_root = ch;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019