~ubuntu-branches/ubuntu/wily/gsasl/wily-proposed

« back to all changes in this revision

Viewing changes to lib/gl/getdelim.c

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-04-14 07:26:51 UTC
  • mfrom: (2.1.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100414072651-hoc2231ulo8onq2x
Tags: 1.4.4-1ubuntu1
* Merge from Debian experimental (LP: #548480). Bugfix only release.
  Remaining changes:
  - debian/rules: Include clean-la.mk from cdbs to clean up the
    dependency_libs field in libgsasl.la.
* debian/control: drop libgsasl7 Depends on libgcrypt to what we have in
  Lucid (1.4.4-5). See Debian bug #564661.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* getdelim.c --- Implementation of replacement getdelim function.
2
 
   Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007,
3
 
   2008, 2009 Free Software Foundation, Inc.
 
2
   Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008,
 
3
   2009, 2010 Free Software Foundation, Inc.
4
4
 
5
5
   This program is free software; you can redistribute it and/or
6
6
   modify it under the terms of the GNU Lesser General Public License as
21
21
 
22
22
#include <config.h>
23
23
 
 
24
/* Don't use __attribute__ __nonnull__ in this compilation unit.  Otherwise gcc
 
25
   optimizes away the lineptr == NULL || n == NULL || fp == NULL tests below.  */
 
26
#define _GL_ARG_NONNULL(params)
 
27
 
24
28
#include <stdio.h>
25
29
 
26
30
#include <limits.h>
34
38
 
35
39
#if USE_UNLOCKED_IO
36
40
# include "unlocked-io.h"
37
 
# define getc_maybe_unlocked(fp)        getc(fp)
 
41
# define getc_maybe_unlocked(fp)        getc(fp)
38
42
#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
39
43
# undef flockfile
40
44
# undef funlockfile
41
45
# define flockfile(x) ((void) 0)
42
46
# define funlockfile(x) ((void) 0)
43
 
# define getc_maybe_unlocked(fp)        getc(fp)
 
47
# define getc_maybe_unlocked(fp)        getc(fp)
44
48
#else
45
 
# define getc_maybe_unlocked(fp)        getc_unlocked(fp)
 
49
# define getc_maybe_unlocked(fp)        getc_unlocked(fp)
46
50
#endif
47
51
 
48
52
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
71
75
      *n = 120;
72
76
      new_lineptr = (char *) realloc (*lineptr, *n);
73
77
      if (new_lineptr == NULL)
74
 
        {
75
 
          result = -1;
76
 
          goto unlock_return;
77
 
        }
 
78
        {
 
79
          result = -1;
 
80
          goto unlock_return;
 
81
        }
78
82
      *lineptr = new_lineptr;
79
83
    }
80
84
 
84
88
 
85
89
      i = getc_maybe_unlocked (fp);
86
90
      if (i == EOF)
87
 
        {
88
 
          result = -1;
89
 
          break;
90
 
        }
 
91
        {
 
92
          result = -1;
 
93
          break;
 
94
        }
91
95
 
92
96
      /* Make enough space for len+1 (for final NUL) bytes.  */
93
97
      if (cur_len + 1 >= *n)
94
 
        {
95
 
          size_t needed_max =
96
 
            SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
97
 
          size_t needed = 2 * *n + 1;   /* Be generous. */
98
 
          char *new_lineptr;
99
 
 
100
 
          if (needed_max < needed)
101
 
            needed = needed_max;
102
 
          if (cur_len + 1 >= needed)
103
 
            {
104
 
              result = -1;
105
 
              errno = EOVERFLOW;
106
 
              goto unlock_return;
107
 
            }
108
 
 
109
 
          new_lineptr = (char *) realloc (*lineptr, needed);
110
 
          if (new_lineptr == NULL)
111
 
            {
112
 
              result = -1;
113
 
              goto unlock_return;
114
 
            }
115
 
 
116
 
          *lineptr = new_lineptr;
117
 
          *n = needed;
118
 
        }
 
98
        {
 
99
          size_t needed_max =
 
100
            SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
 
101
          size_t needed = 2 * *n + 1;   /* Be generous. */
 
102
          char *new_lineptr;
 
103
 
 
104
          if (needed_max < needed)
 
105
            needed = needed_max;
 
106
          if (cur_len + 1 >= needed)
 
107
            {
 
108
              result = -1;
 
109
              errno = EOVERFLOW;
 
110
              goto unlock_return;
 
111
            }
 
112
 
 
113
          new_lineptr = (char *) realloc (*lineptr, needed);
 
114
          if (new_lineptr == NULL)
 
115
            {
 
116
              result = -1;
 
117
              goto unlock_return;
 
118
            }
 
119
 
 
120
          *lineptr = new_lineptr;
 
121
          *n = needed;
 
122
        }
119
123
 
120
124
      (*lineptr)[cur_len] = i;
121
125
      cur_len++;
122
126
 
123
127
      if (i == delimiter)
124
 
        break;
 
128
        break;
125
129
    }
126
130
  (*lineptr)[cur_len] = '\0';
127
131
  result = cur_len ? cur_len : result;