View | Details | Raw Unified | Return to bug 17694
Collapse All | Expand All

(-)ansi.c (-13 / +23 lines)
Lines 103-118 Link Here
103
	size_t n;
103
	size_t n;
104
{
104
{
105
	char const *e;
105
	char const *e;
106
	wchar_t wc;
106
	int cnt = 0;
107
	int cnt = 0;
107
108
108
	if (!pwcs || !s)
109
	if (!s)
109
		return (-1);
110
		return (-1);
110
111
111
	while (n-- > 0) {
112
	for (;;) {
112
		*pwcs = sgetrune(s, MB_LEN_MAX, &e);
113
		wc = sgetrune(s, MB_LEN_MAX, &e);
113
		if (*pwcs == _INVALID_RUNE)
114
		if (wc == _INVALID_RUNE)
114
			return (-1);
115
			return (-1);
115
		if (*pwcs++ == 0)
116
		if (pwcs) {
117
			if (n-- <= 0)
118
				break;
119
			*pwcs++ = wc;
120
		}
121
		if (wc == 0)
116
			break;
122
			break;
117
		s = e;
123
		s = e;
118
		++cnt;
124
		++cnt;
Lines 129-151 Link Here
129
	char *e;
135
	char *e;
130
	int cnt, nb;
136
	int cnt, nb;
131
137
132
	if (!pwcs || !s || n > INT_MAX)
138
	if (!pwcs || n > INT_MAX)
133
		return (-1);
139
		return (-1);
134
140
135
	nb = n;
136
	cnt = 0;
141
	cnt = 0;
137
	while (nb > 0) {
142
	for (;;) {
138
		if (*pwcs == 0) {
143
		if (*pwcs == 0) {
139
			*s = 0;
144
			if (s)
145
				*s = 0;
140
			break;
146
			break;
141
		}
147
		}
142
		if (!sputrune(*pwcs++, s, nb, &e))
148
		if (!(nb = sputrune(*pwcs++, s, nb, &e)))
143
			return (-1);		/* encoding error */
149
			return (-1);		/* encoding error */
144
		if (!e)			/* too long */
150
		if (!e)			/* too long */
145
			return (cnt);
151
			return (cnt);
146
		cnt += e - s;
152
		cnt += nb;
147
		nb -= e - s;
153
		n -= nb;
148
		s = e;
154
		if (s) {
155
			if (n <= 0)
156
				break;
157
			s = e;
158
		}
149
	}
159
	}
150
	return (cnt);
160
	return (cnt);
151
}
161
}

Return to bug 17694