Hi fellow hacker,

attached are 2 clean-up patches inside netrc.c. They are mostly
harmless but I wanted to get people's feelings before going ahead and
pushing them.

Any objections or thoughts?

Thanks!
Julien
From 6c2623ab91cb51ac705c535ab2fb097c38f39914 Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <julien.chaffr...@gmail.com>
Date: Fri, 28 Jan 2011 08:34:17 -0800
Subject: [PATCH 2/2] netrc: Removed dead code.

The main has not been updated from some time and is out of sync with
the code. The code is now tested by several test cases so no need for
a seperate code path.
---
 lib/netrc.c |   23 -----------------------
 1 files changed, 0 insertions(+), 23 deletions(-)

diff --git a/lib/netrc.c b/lib/netrc.c
index 1934d6a..7e0447d 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -50,12 +50,6 @@
 /* The last #include file should be: */
 #include "memdebug.h"
 
-/* Debug this single source file with:
-   'make netrc' then run './netrc'!
-
-   Oh, make sure you have a .netrc file too ;-)
- */
-
 /* Get user and password from .netrc when given a machine name */
 
 enum host_lookup_state {
@@ -230,20 +224,3 @@ int Curl_parsenetrc(const char *host,
 
   return retcode;
 }
-
-#ifdef _NETRC_DEBUG
-int main(int argc, argv_item_t argv[])
-{
-  char login[64]="";
-  char password[64]="";
-
-  if(argc<2)
-    return -1;
-
-  if(0 == ParseNetrc(argv[1], login, password)) {
-    printf("HOST: %s LOGIN: %s PASSWORD: %s\n",
-           argv[1], login, password);
-  }
-}
-
-#endif
-- 
1.7.1

From a075b38adea73ff1578984b263eed92a9237d4d2 Mon Sep 17 00:00:00 2001
From: Julien Chaffraix <julien.chaffr...@gmail.com>
Date: Fri, 28 Jan 2011 08:20:37 -0800
Subject: [PATCH 1/2] netrc: Tightened up the type checks.

The state should not be anonymous so that we can check if the values
are fine. Added 2 unreachables states to the switch as a result of this
change.
---
 lib/netrc.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/netrc.c b/lib/netrc.c
index e944325..1934d6a 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -58,7 +58,7 @@
 
 /* Get user and password from .netrc when given a machine name */
 
-enum {
+enum host_lookup_state {
   NOTHING,
   HOSTFOUND,    /* the 'machine' keyword was found */
   HOSTCOMPLETE, /* the machine name following the keyword was found too */
@@ -83,7 +83,7 @@ int Curl_parsenetrc(const char *host,
   char *home = NULL;
   bool home_alloc = FALSE;
   bool netrc_alloc = FALSE;
-  int state=NOTHING;
+  enum host_lookup_state state=NOTHING;
 
   char state_login=0;      /* Found a login keyword */
   char state_password=0;   /* Found a password keyword */
@@ -210,6 +210,10 @@ int Curl_parsenetrc(const char *host,
             state_our_login = FALSE;
           }
           break;
+        case HOSTCOMPLETE:
+        case HOSTEND:
+            /* Should not be reached. */
+            DEBUGASSERT(0);
         } /* switch (state) */
 
         tok = strtok_r(NULL, " \t\n", &tok_buf);
-- 
1.7.1

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to