Fix off-by-one error in the maxlen parameter handling.
authorPeter Eisentraut
Tue, 18 Mar 2003 22:09:37 +0000 (22:09 +0000)
committerPeter Eisentraut
Tue, 18 Mar 2003 22:09:37 +0000 (22:09 +0000)
src/bin/pg_dump/sprompt.c
src/bin/psql/sprompt.c

index 767d984ac26b37ed19c1c0df0bbb66c347d135ca..9c0d4f0db6af6512997ace01e0f6ce0528674435 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/sprompt.c,v 1.3 2002/09/11 17:32:37 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/sprompt.c,v 1.4 2003/03/18 22:09:37 petere Exp $
  */
 
 /*
@@ -45,7 +45,7 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
                t;
 #endif
 
-   destination = (char *) malloc(maxlen + 2);
+   destination = (char *) malloc(maxlen + 1);
    if (!destination)
        return NULL;
 
@@ -83,7 +83,7 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
        fflush(termout);
    }
 
-   if (fgets(destination, maxlen, termin) == NULL)
+   if (fgets(destination, maxlen + 1, termin) == NULL)
        destination[0] = '\0';
 
    length = strlen(destination);
index d05b294bfa5efa16ca63bdc89d80cd034799422b..46ac2d97ba67ac5e7b14aa87b6e6667ef817d304 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.3 2002/09/04 20:31:36 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.4 2003/03/18 22:09:37 petere Exp $
  */
 
 
@@ -44,7 +44,7 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
                t;
 #endif
 
-   destination = (char *) malloc(maxlen + 2);
+   destination = (char *) malloc(maxlen + 1);
    if (!destination)
        return NULL;
 
@@ -82,7 +82,7 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
        fflush(termout);
    }
 
-   if (fgets(destination, maxlen, termin) == NULL)
+   if (fgets(destination, maxlen + 1, termin) == NULL)
        destination[0] = '\0';
 
    length = strlen(destination);