guint len, inlen, added = 0;
gboolean got_sp, finished = FALSE;
- if (size > sizeof (buf)) {
- len = sizeof (buf);
- }
- else {
- len = size;
+ len = size;
+ if (size <= sizeof (buf)) {
finished = TRUE;
}
inlen = sizeof (buf) - 1;
got_sp = FALSE;
t--;
}
+ if (inlen < 2) {
+ /*
+ * Inlen is too small to continue, hence we need more iteration to
+ * avoid splitted \r\n
+ */
+ h --;
+ finished = FALSE;
+ break;
+ }
/* Replace a single \n or \r with \r\n */
if (*h == '\n' && (h == *start || *(h - 1) != '\r')) {
*t++ = '\r';
len--;
continue;
}
- else if (inlen < 2) {
- /*
- * Inlen is too small to continue, hence we need more iteration to
- * avoid splitted \r\n
- */
- finished = FALSE;
- break;
- }
}
else if (g_ascii_isspace (*h)) {
if (got_sp) {
guint len, inlen, added = 0;
gboolean finished = FALSE;
- if (size > sizeof (buf)) {
- len = sizeof (buf);
- }
- else {
- len = size;
+ len = size;
+ if (size <= sizeof (buf)) {
finished = TRUE;
}
inlen = sizeof (buf) - 1;
while (len && inlen) {
if (*h == '\r' || *h == '\n') {
+ if (inlen < 2) {
+ /*
+ * Inlen is too small to continue, hence we need more iteration to
+ * avoid splitted \r\n
+ */
+ h --;
+ finished = FALSE;
+ break;
+ }
/* Replace a single \n or \r with \r\n */
if (*h == '\n' && (h == *start || *(h - 1) != '\r')) {
*t++ = '\r';
len--;
continue;
}
- else if (inlen < 2) {
- /*
- * Inlen is too small to continue, hence we need more iteration to
- * avoid splitted \r\n
- */
- finished = FALSE;
- break;
- }
}
*t++ = *h++;
inlen--;