1
1

Refactoring of endless loops and some type accuracy.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2012-10-21 18:16:44 +04:00
родитель b2f97443e2
Коммит 6c94ef16ec
11 изменённых файлов: 143 добавлений и 150 удалений

Просмотреть файл

@ -2227,7 +2227,7 @@ learn_key (void)
endtime.tv_sec++; endtime.tv_sec++;
} }
tty_nodelay (TRUE); tty_nodelay (TRUE);
for (;;) while (TRUE)
{ {
while ((c = tty_lowlevel_getch ()) == -1) while ((c = tty_lowlevel_getch ()) == -1)
{ {

Просмотреть файл

@ -135,9 +135,10 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */ bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
j = 0; j = 0;
k = g_malloc (bytes); k = g_malloc (bytes);
for (;;) while (TRUE)
{ {
int c; int c;
c = rxvt_getc (); c = rxvt_getc ();
if (c < 0) if (c < 0)
break; break;

Просмотреть файл

@ -991,32 +991,32 @@ diff_two_paths (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{ {
p = my_first; p = my_first;
q = my_second; q = my_second;
for (;;) while (TRUE)
{ {
r = strchr (p, PATH_SEP); r = strchr (p, PATH_SEP);
s = strchr (q, PATH_SEP); s = strchr (q, PATH_SEP);
if (!r || !s) if (r == NULL || s == NULL)
break; break;
*r = 0; *r = '\0';
*s = 0; *s = '\0';
if (strcmp (p, q)) if (strcmp (p, q) != 0)
{ {
*r = PATH_SEP; *r = PATH_SEP;
*s = PATH_SEP; *s = PATH_SEP;
break; break;
} }
else
{ *r = PATH_SEP;
*r = PATH_SEP; *s = PATH_SEP;
*s = PATH_SEP;
}
p = r + 1; p = r + 1;
q = s + 1; q = s + 1;
} }
p--; p--;
for (i = 0; (p = strchr (p + 1, PATH_SEP)) != NULL; i++); for (i = 0; (p = strchr (p + 1, PATH_SEP)) != NULL; i++)
;
currlen = (i + 1) * 3 + strlen (q) + 1; currlen = (i + 1) * 3 + strlen (q) + 1;
if (j) if (j != 0)
{ {
if (currlen < prevlen) if (currlen < prevlen)
g_free (buf); g_free (buf);

Просмотреть файл

@ -977,7 +977,7 @@ my_type_of (int c)
const char option_chars_move_whole_word[] = const char option_chars_move_whole_word[] =
"!=&|<>^~ !:;, !'!`!.?!\"!( !) !{ !} !Aa0 !+-*/= |<> ![ !] !\\#! "; "!=&|<>^~ !:;, !'!`!.?!\"!( !) !{ !} !Aa0 !+-*/= |<> ![ !] !\\#! ";
if (!c) if (c == 0)
return 0; return 0;
if (c == '!') if (c == '!')
{ {
@ -1014,27 +1014,27 @@ my_type_of (int c)
static void static void
edit_left_word_move (WEdit * edit, int s) edit_left_word_move (WEdit * edit, int s)
{ {
for (;;) while (TRUE)
{ {
int c1, c2; int c1, c2;
if (edit->column_highlight if (edit->column_highlight
&& edit->mark1 != edit->mark2 && edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1)) && edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1))
break; break;
edit_cursor_move (edit, -1); edit_cursor_move (edit, -1);
if (!edit->curs1) if (edit->curs1 == 0)
break; break;
c1 = edit_get_byte (edit, edit->curs1 - 1); c1 = edit_get_byte (edit, edit->curs1 - 1);
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->curs1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if (!(my_type_of (c1) & my_type_of (c2))) if ((my_type_of (c1) & my_type_of (c2)) == 0)
break; break;
if (isspace (c1) && !isspace (c2)) if (isspace (c1) && !isspace (c2))
break; break;
if (s) if (s != 0 && !isspace (c1) && isspace (c2))
if (!isspace (c1) && isspace (c2)) break;
break;
} }
} }
@ -1052,9 +1052,10 @@ edit_left_word_move_cmd (WEdit * edit)
static void static void
edit_right_word_move (WEdit * edit, int s) edit_right_word_move (WEdit * edit, int s)
{ {
for (;;) while (TRUE)
{ {
int c1, c2; int c1, c2;
if (edit->column_highlight if (edit->column_highlight
&& edit->mark1 != edit->mark2 && edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_eol (edit, edit->curs1)) && edit->over_col == 0 && edit->curs1 == edit_eol (edit, edit->curs1))
@ -1066,13 +1067,12 @@ edit_right_word_move (WEdit * edit, int s)
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->curs1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if (!(my_type_of (c1) & my_type_of (c2))) if ((my_type_of (c1) & my_type_of (c2)) == 0)
break; break;
if (isspace (c1) && !isspace (c2)) if (isspace (c1) && !isspace (c2))
break; break;
if (s) if (s != 0 && !isspace (c1) && isspace (c2))
if (!isspace (c1) && isspace (c2)) break;
break;
} }
} }
@ -1194,18 +1194,17 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi
static void static void
edit_right_delete_word (WEdit * edit) edit_right_delete_word (WEdit * edit)
{ {
int c1, c2; while (edit->curs1 < edit->last_byte)
for (;;)
{ {
if (edit->curs1 >= edit->last_byte) int c1, c2;
break;
c1 = edit_delete (edit, TRUE); c1 = edit_delete (edit, TRUE);
c2 = edit_get_byte (edit, edit->curs1); c2 = edit_get_byte (edit, edit->curs1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if ((isspace (c1) == 0) != (isspace (c2) == 0)) if ((isspace (c1) == 0) != (isspace (c2) == 0))
break; break;
if (!(my_type_of (c1) & my_type_of (c2))) if ((my_type_of (c1) & my_type_of (c2)) == 0)
break; break;
} }
} }
@ -1215,18 +1214,17 @@ edit_right_delete_word (WEdit * edit)
static void static void
edit_left_delete_word (WEdit * edit) edit_left_delete_word (WEdit * edit)
{ {
int c1, c2; while (edit->curs1 > 0)
for (;;)
{ {
if (edit->curs1 <= 0) int c1, c2;
break;
c1 = edit_backspace (edit, TRUE); c1 = edit_backspace (edit, TRUE);
c2 = edit_get_byte (edit, edit->curs1 - 1); c2 = edit_get_byte (edit, edit->curs1 - 1);
if (c1 == '\n' || c2 == '\n') if (c1 == '\n' || c2 == '\n')
break; break;
if ((isspace (c1) == 0) != (isspace (c2) == 0)) if ((isspace (c1) == 0) != (isspace (c2) == 0))
break; break;
if (!(my_type_of (c1) & my_type_of (c2))) if ((my_type_of (c1) & my_type_of (c2)) == 0)
break; break;
} }
} }
@ -1473,11 +1471,12 @@ edit_auto_indent (WEdit * edit)
{ {
off_t p; off_t p;
char c; char c;
p = edit->curs1; p = edit->curs1;
/* use the previous line as a template */ /* use the previous line as a template */
p = edit_move_backward (edit, p, 1); p = edit_move_backward (edit, p, 1);
/* copy the leading whitespace of the line */ /* copy the leading whitespace of the line */
for (;;) while (TRUE)
{ /* no range check - the line _is_ \n-terminated */ { /* no range check - the line _is_ \n-terminated */
c = edit_get_byte (edit, p++); c = edit_get_byte (edit, p++);
if (c != ' ' && c != '\t') if (c != ' ' && c != '\t')
@ -1558,7 +1557,7 @@ check_and_wrap_line (WEdit * edit)
if (edit->curs_col < option_word_wrap_line_length) if (edit->curs_col < option_word_wrap_line_length)
return; return;
curs = edit->curs1; curs = edit->curs1;
for (;;) while (TRUE)
{ {
curs--; curs--;
c = edit_get_byte (edit, curs); c = edit_get_byte (edit, curs);

Просмотреть файл

@ -615,7 +615,7 @@ read_one_line (char **line, FILE * f)
/* not reallocate string too often */ /* not reallocate string too often */
p = g_string_sized_new (64); p = g_string_sized_new (64);
for (;;) while (TRUE)
{ {
int c; int c;
@ -906,7 +906,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
if (!edit->defines) if (!edit->defines)
edit->defines = g_tree_new ((GCompareFunc) strcmp); edit->defines = g_tree_new ((GCompareFunc) strcmp);
for (;;) while (TRUE)
{ {
char **a; char **a;
size_t len; size_t len;
@ -915,47 +915,41 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
l = 0; l = 0;
len = read_one_line (&l, f); len = read_one_line (&l, f);
if (len == 0) if (len != 0)
{ xx_lowerize_line (edit, l, len);
if (g)
{
fclose (f);
f = g;
g = 0;
line = save_line + 1;
MC_PTR_FREE (error_file_name);
MC_PTR_FREE (l);
len = read_one_line (&l, f);
if (len == 0)
break;
else
xx_lowerize_line (edit, l, len);
}
else
{
break;
}
}
else else
{ {
if (g == NULL)
break;
fclose (f);
f = g;
g = NULL;
line = save_line + 1;
MC_PTR_FREE (error_file_name);
MC_PTR_FREE (l);
len = read_one_line (&l, f);
if (len == 0)
break;
xx_lowerize_line (edit, l, len); xx_lowerize_line (edit, l, len);
} }
argc = get_args (l, args, args_size); argc = get_args (l, args, args_size);
a = args + 1; a = args + 1;
if (!args[0]) if (args[0] == NULL)
{ {
/* do nothing */ /* do nothing */
} }
else if (!strcmp (args[0], "include")) else if (strcmp (args[0], "include") == 0)
{ {
if (g || argc != 2) if (g != NULL || argc != 2)
{ {
result = line; result = line;
break; break;
} }
g = f; g = f;
f = open_include_file (args[1]); f = open_include_file (args[1]);
if (!f) if (f == NULL)
{ {
MC_PTR_FREE (error_file_name); MC_PTR_FREE (error_file_name);
result = line; result = line;
@ -964,19 +958,19 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
save_line = line; save_line = line;
line = 0; line = 0;
} }
else if (!strcmp (args[0], "caseinsensitive")) else if (strcmp (args[0], "caseinsensitive") == 0)
{ {
edit->is_case_insensitive = TRUE; edit->is_case_insensitive = TRUE;
} }
else if (!strcmp (args[0], "wholechars")) else if (strcmp (args[0], "wholechars") == 0)
{ {
check_a; check_a;
if (!strcmp (*a, "left")) if (strcmp (*a, "left") == 0)
{ {
a++; a++;
g_strlcpy (whole_left, *a, sizeof (whole_left)); g_strlcpy (whole_left, *a, sizeof (whole_left));
} }
else if (!strcmp (*a, "right")) else if (strcmp (*a, "right") == 0)
{ {
a++; a++;
g_strlcpy (whole_right, *a, sizeof (whole_right)); g_strlcpy (whole_right, *a, sizeof (whole_right));
@ -989,12 +983,12 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
a++; a++;
check_not_a; check_not_a;
} }
else if (!strcmp (args[0], "context")) else if (strcmp (args[0], "context") == 0)
{ {
check_a; check_a;
if (num_contexts == -1) if (num_contexts == -1)
{ {
if (strcmp (*a, "default")) if (strcmp (*a, "default") != 0)
{ /* first context is the default */ { /* first context is the default */
break_a; break_a;
} }
@ -1009,30 +1003,30 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
/* Terminate previous context. */ /* Terminate previous context. */
r[num_contexts - 1]->keyword[num_words] = NULL; r[num_contexts - 1]->keyword[num_words] = NULL;
c = r[num_contexts] = g_malloc0 (sizeof (struct context_rule)); c = r[num_contexts] = g_malloc0 (sizeof (struct context_rule));
if (!strcmp (*a, "exclusive")) if (strcmp (*a, "exclusive") == 0)
{ {
a++; a++;
c->between_delimiters = 1; c->between_delimiters = 1;
} }
check_a; check_a;
if (!strcmp (*a, "whole")) if (strcmp (*a, "whole") == 0)
{ {
a++; a++;
c->whole_word_chars_left = g_strdup (whole_left); c->whole_word_chars_left = g_strdup (whole_left);
c->whole_word_chars_right = g_strdup (whole_right); c->whole_word_chars_right = g_strdup (whole_right);
} }
else if (!strcmp (*a, "wholeleft")) else if (strcmp (*a, "wholeleft") == 0)
{ {
a++; a++;
c->whole_word_chars_left = g_strdup (whole_left); c->whole_word_chars_left = g_strdup (whole_left);
} }
else if (!strcmp (*a, "wholeright")) else if (strcmp (*a, "wholeright") == 0)
{ {
a++; a++;
c->whole_word_chars_right = g_strdup (whole_right); c->whole_word_chars_right = g_strdup (whole_right);
} }
check_a; check_a;
if (!strcmp (*a, "linestart")) if (strcmp (*a, "linestart") == 0)
{ {
a++; a++;
c->line_start_left = 1; c->line_start_left = 1;
@ -1040,7 +1034,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
check_a; check_a;
c->left = g_strdup (*a++); c->left = g_strdup (*a++);
check_a; check_a;
if (!strcmp (*a, "linestart")) if (strcmp (*a, "linestart") == 0)
{ {
a++; a++;
c->line_start_right = 1; c->line_start_right = 1;
@ -1055,17 +1049,17 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
c->keyword[0] = g_malloc0 (sizeof (struct key_word)); c->keyword[0] = g_malloc0 (sizeof (struct key_word));
subst_defines (edit->defines, a, &args[1024]); subst_defines (edit->defines, a, &args[1024]);
fg = *a; fg = *a;
if (*a) if (*a != '\0')
a++; a++;
bg = *a; bg = *a;
if (*a) if (*a != '\0')
a++; a++;
attrs = *a; attrs = *a;
if (*a) if (*a != '\0')
a++; a++;
g_strlcpy (last_fg, fg ? fg : "", sizeof (last_fg)); g_strlcpy (last_fg, fg != NULL ? fg : "", sizeof (last_fg));
g_strlcpy (last_bg, bg ? bg : "", sizeof (last_bg)); g_strlcpy (last_bg, bg != NULL ? bg : "", sizeof (last_bg));
g_strlcpy (last_attrs, attrs ? attrs : "", sizeof (last_attrs)); g_strlcpy (last_attrs, attrs != NULL ? attrs : "", sizeof (last_attrs));
c->keyword[0]->color = this_try_alloc_color_pair (fg, bg, attrs); c->keyword[0]->color = this_try_alloc_color_pair (fg, bg, attrs);
c->keyword[0]->keyword = g_strdup (" "); c->keyword[0]->keyword = g_strdup (" ");
check_not_a; check_not_a;
@ -1080,16 +1074,16 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
r = tmp; r = tmp;
} }
} }
else if (!strcmp (args[0], "spellcheck")) else if (strcmp (args[0], "spellcheck") == 0)
{ {
if (!c) if (c == NULL)
{ {
result = line; result = line;
break; break;
} }
c->spelling = TRUE; c->spelling = TRUE;
} }
else if (!strcmp (args[0], "keyword")) else if (strcmp (args[0], "keyword") == 0)
{ {
struct key_word *k; struct key_word *k;
@ -1097,30 +1091,30 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
break_a; break_a;
check_a; check_a;
k = r[num_contexts - 1]->keyword[num_words] = g_malloc0 (sizeof (struct key_word)); k = r[num_contexts - 1]->keyword[num_words] = g_malloc0 (sizeof (struct key_word));
if (!strcmp (*a, "whole")) if (strcmp (*a, "whole") == 0)
{ {
a++; a++;
k->whole_word_chars_left = g_strdup (whole_left); k->whole_word_chars_left = g_strdup (whole_left);
k->whole_word_chars_right = g_strdup (whole_right); k->whole_word_chars_right = g_strdup (whole_right);
} }
else if (!strcmp (*a, "wholeleft")) else if (strcmp (*a, "wholeleft") == 0)
{ {
a++; a++;
k->whole_word_chars_left = g_strdup (whole_left); k->whole_word_chars_left = g_strdup (whole_left);
} }
else if (!strcmp (*a, "wholeright")) else if (strcmp (*a, "wholeright") == 0)
{ {
a++; a++;
k->whole_word_chars_right = g_strdup (whole_right); k->whole_word_chars_right = g_strdup (whole_right);
} }
check_a; check_a;
if (!strcmp (*a, "linestart")) if (strcmp (*a, "linestart") == 0)
{ {
a++; a++;
k->line_start = 1; k->line_start = 1;
} }
check_a; check_a;
if (!strcmp (*a, "whole")) if (strcmp (*a, "whole") == 0)
{ {
break_a; break_a;
} }
@ -1128,19 +1122,19 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
k->first = *k->keyword; k->first = *k->keyword;
subst_defines (edit->defines, a, &args[1024]); subst_defines (edit->defines, a, &args[1024]);
fg = *a; fg = *a;
if (*a) if (*a != '\0')
a++; a++;
bg = *a; bg = *a;
if (*a) if (*a != '\0')
a++; a++;
attrs = *a; attrs = *a;
if (*a) if (*a != '\0')
a++; a++;
if (!fg) if (fg == NULL)
fg = last_fg; fg = last_fg;
if (!bg) if (bg == NULL)
bg = last_bg; bg = last_bg;
if (!attrs) if (attrs == NULL)
attrs = last_attrs; attrs = last_attrs;
k->color = this_try_alloc_color_pair (fg, bg, attrs); k->color = this_try_alloc_color_pair (fg, bg, attrs);
check_not_a; check_not_a;
@ -1162,11 +1156,11 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
{ {
/* do nothing for comment */ /* do nothing for comment */
} }
else if (!strcmp (args[0], "file")) else if (strcmp (args[0], "file") == 0)
{ {
break; break;
} }
else if (!strcmp (args[0], "define")) else if (strcmp (args[0], "define") == 0)
{ {
char *key = *a++; char *key = *a++;
char **argv; char **argv;
@ -1182,9 +1176,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
argv = g_new (char *, argc - 1); argv = g_new (char *, argc - 1);
g_tree_insert (edit->defines, key, argv); g_tree_insert (edit->defines, key, argv);
while (*a != NULL) while (*a != NULL)
{
*argv++ = g_strdup (*a++); *argv++ = g_strdup (*a++);
}
*argv = NULL; *argv = NULL;
} }
else else
@ -1204,28 +1196,24 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
r[num_contexts] = NULL; r[num_contexts] = NULL;
} }
if (!edit->rules[0]) if (edit->rules[0] == NULL)
MC_PTR_FREE (edit->rules); MC_PTR_FREE (edit->rules);
if (result) if (result == 0)
return result;
if (num_contexts == -1)
{
return line;
}
{ {
char *first_chars, *p; char *first_chars, *p;
if (num_contexts == -1)
return line;
first_chars = g_malloc0 (max_alloc_words_per_context + 2); first_chars = g_malloc0 (max_alloc_words_per_context + 2);
for (i = 0; edit->rules[i]; i++) for (i = 0; edit->rules[i] != NULL; i++)
{ {
c = edit->rules[i]; c = edit->rules[i];
p = first_chars; p = first_chars;
*p++ = (char) 1; *p++ = (char) 1;
for (j = 1; c->keyword[j]; j++) for (j = 1; c->keyword[j] != NULL; j++)
*p++ = c->keyword[j]->first; *p++ = c->keyword[j]->first;
*p = '\0'; *p = '\0';
c->keyword_first_chars = g_strdup (first_chars); c->keyword_first_chars = g_strdup (first_chars);
@ -1265,7 +1253,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
} }
args[0] = NULL; args[0] = NULL;
for (;;) while (TRUE)
{ {
line++; line++;
MC_PTR_FREE (l); MC_PTR_FREE (l);

Просмотреть файл

@ -230,7 +230,8 @@ static inline int
line_pixel_length (unsigned char *t, long b, int l) line_pixel_length (unsigned char *t, long b, int l)
{ {
int x = 0, c, xn = 0; int x = 0, c, xn = 0;
for (;;)
while (TRUE)
{ {
c = t[b]; c = t[b];
switch (c) switch (c)
@ -286,12 +287,15 @@ static inline int
word_start (unsigned char *t, int q, int size) word_start (unsigned char *t, int q, int size)
{ {
int i = q; int i = q;
if (t[q] == ' ' || t[q] == '\t') if (t[q] == ' ' || t[q] == '\t')
return next_word_start (t, q, size); return next_word_start (t, q, size);
for (;;)
while (TRUE)
{ {
int c; int c;
if (!i)
if (i == 0)
return -1; return -1;
c = t[i - 1]; c = t[i - 1];
if (c == '\n') if (c == '\n')
@ -309,13 +313,15 @@ static inline void
format_this (unsigned char *t, int size, int indent) format_this (unsigned char *t, int size, int indent)
{ {
int q = 0, ww; int q = 0, ww;
strip_newlines (t, size); strip_newlines (t, size);
ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent; ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent;
if (ww < FONT_MEAN_WIDTH * 2) if (ww < FONT_MEAN_WIDTH * 2)
ww = FONT_MEAN_WIDTH * 2; ww = FONT_MEAN_WIDTH * 2;
for (;;) while (TRUE)
{ {
int p; int p;
q = line_pixel_length (t, q, ww); q = line_pixel_length (t, q, ww);
if (q > size) if (q > size)
break; break;
@ -330,7 +336,7 @@ format_this (unsigned char *t, int size, int indent)
q = p; q = p;
if (q == -1) /* end of paragraph */ if (q == -1) /* end of paragraph */
break; break;
if (q) if (q != 0)
t[q - 1] = '\n'; t[q - 1] = '\n';
} }
} }
@ -353,6 +359,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
{ {
long cursor; long cursor;
int i, c = 0; int i, c = 0;
cursor = edit->curs1; cursor = edit->curs1;
if (indent) if (indent)
while (strchr ("\t ", edit_get_byte (edit, p))) while (strchr ("\t ", edit_get_byte (edit, p)))

Просмотреть файл

@ -893,7 +893,7 @@ get_line_at (int file_fd, char *buf, int buf_size, int *pos, int *n_read, gboole
char ch = 0; char ch = 0;
int i = 0; int i = 0;
for (;;) while (TRUE)
{ {
if (*pos >= *n_read) if (*pos >= *n_read)
{ {

Просмотреть файл

@ -1269,9 +1269,11 @@ safe_read (int fd, void *buf, size_t count)
enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 }; enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
/* *INDENT-ON* */ /* *INDENT-ON* */
for (;;) while (TRUE)
{ {
ssize_t result = read (fd, buf, count); ssize_t result;
result = read (fd, buf, count);
if (0 <= result) if (0 <= result)
return result; return result;

Просмотреть файл

@ -192,16 +192,17 @@ fish_load_script_from_file (const char *hostname, const char *script_name, const
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static int static int
fish_decode_reply (char *s, int was_garbage) fish_decode_reply (char *s, gboolean was_garbage)
{ {
int code; int code;
if (!sscanf (s, "%d", &code))
if (sscanf (s, "%d", &code) == 0)
{ {
code = 500; code = 500;
return 5; return 5;
} }
if (code < 100) if (code < 100)
return was_garbage ? ERROR : (!code ? COMPLETE : PRELIM); return was_garbage ? ERROR : (code == 0 ? COMPLETE : PRELIM);
return code / 100; return code / 100;
} }
@ -212,25 +213,23 @@ static int
fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len) fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
{ {
char answer[BUF_1K]; char answer[BUF_1K];
int was_garbage = 0; gboolean was_garbage = FALSE;
for (;;) while (TRUE)
{ {
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n')) if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
{ {
if (string_buf) if (string_buf != NULL)
*string_buf = 0; *string_buf = '\0';
return 4; return 4;
} }
if (strncmp (answer, "### ", 4)) if (strncmp (answer, "### ", 4) == 0)
{ return fish_decode_reply (answer + 4, was_garbage ? 1 : 0);
was_garbage = 1;
if (string_buf) was_garbage = TRUE;
g_strlcpy (string_buf, answer, string_len); if (string_buf != NULL)
} g_strlcpy (string_buf, answer, string_len);
else
return fish_decode_reply (answer + 4, was_garbage);
} }
} }

Просмотреть файл

@ -377,31 +377,31 @@ ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_le
char answer[BUF_1K]; char answer[BUF_1K];
int i; int i;
for (;;) while (TRUE)
{ {
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n')) if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
{ {
if (string_buf) if (string_buf != NULL)
*string_buf = 0; *string_buf = '\0';
code = 421; code = 421;
return 4; return 4;
} }
switch (sscanf (answer, "%d", &code)) switch (sscanf (answer, "%d", &code) != 0)
{ {
case 0: case 0:
if (string_buf) if (string_buf != NULL)
g_strlcpy (string_buf, answer, string_len); g_strlcpy (string_buf, answer, string_len);
code = 500; code = 500;
return 5; return 5;
case 1: case 1:
if (answer[3] == '-') if (answer[3] == '-')
{ {
while (1) while (TRUE)
{ {
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n')) if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
{ {
if (string_buf) if (string_buf != NULL)
*string_buf = 0; *string_buf = '\0';
code = 421; code = 421;
return 4; return 4;
} }
@ -409,7 +409,7 @@ ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_le
break; break;
} }
} }
if (string_buf) if (string_buf != NULL)
g_strlcpy (string_buf, answer, string_len); g_strlcpy (string_buf, answer, string_len);
return code / 100; return code / 100;
} }
@ -432,7 +432,6 @@ ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
SUP->sock = sock; SUP->sock = sock;
SUP->current_dir = NULL; SUP->current_dir = NULL;
if (ftpfs_login_server (me, super, super->path_element->password) != 0) if (ftpfs_login_server (me, super, super->path_element->password) != 0)
{ {
if (cwdir == NULL) if (cwdir == NULL)

Просмотреть файл

@ -765,7 +765,7 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
if (tard == -1) if (tard == -1)
return -1; return -1;
for (;;) while (TRUE)
{ {
size_t h_size; size_t h_size;
@ -774,7 +774,6 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
switch (status) switch (status)
{ {
case STATUS_SUCCESS: case STATUS_SUCCESS:
tar_skip_n_records (archive, tard, (h_size + RECORDSIZE - 1) / RECORDSIZE); tar_skip_n_records (archive, tard, (h_size + RECORDSIZE - 1) / RECORDSIZE);
continue; continue;
@ -788,7 +787,6 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
case STATUS_BADCHECKSUM: case STATUS_BADCHECKSUM:
switch (prev_status) switch (prev_status)
{ {
/* Error on first record */ /* Error on first record */
case STATUS_EOFMARK: case STATUS_EOFMARK:
{ {
@ -818,7 +816,7 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
break; break;
} }
break; break;
}; }
return 0; return 0;
} }