[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
diagnostics: simplify location handling
From: |
Akim Demaille |
Subject: |
diagnostics: simplify location handling |
Date: |
Thu, 24 Oct 2019 18:14:47 +0200 |
Taken from my branch playing with fuzzing.
commit fa9871a2fb6adaca6aa72b75959bac865af81cc8
Author: Akim Demaille <address@hidden>
Date: Mon Oct 21 17:33:32 2019 +0200
diagnostics: simplify location handling
Locations start at line 1. Don't accept line 0.
* src/location.c (location_print): Don't print locations with line 0.
(location_caret): Simplify.
diff --git a/src/location.c b/src/location.c
index 4d545472..357cce7c 100644
--- a/src/location.c
+++ b/src/location.c
@@ -178,10 +178,10 @@ location_print (location loc, FILE *out)
int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0;
res += fprintf (out, "%s",
quotearg_n_style (3, escape_quoting_style,
loc.start.file));
- if (0 <= loc.start.line)
+ if (0 < loc.start.line)
{
res += fprintf (out, ":%d", loc.start.line);
- if (0 <= loc.start.column)
+ if (0 < loc.start.column)
res += fprintf (out, ".%d", loc.start.column);
}
if (loc.start.file != loc.end.file)
@@ -189,14 +189,14 @@ location_print (location loc, FILE *out)
res += fprintf (out, "-%s",
quotearg_n_style (3, escape_quoting_style,
loc.end.file));
- if (0 <= loc.end.line)
+ if (0 < loc.end.line)
{
res += fprintf (out, ":%d", loc.end.line);
if (0 <= end_col)
res += fprintf (out, ".%d", end_col);
}
}
- else if (0 <= loc.end.line)
+ else if (0 < loc.end.line)
{
if (loc.start.line < loc.end.line)
{
@@ -400,7 +400,7 @@ caret_set_column (int col)
void
location_caret (location loc, const char *style, FILE *out)
{
- if (loc.start.column == -1 || loc.start.line == -1)
+ if (!loc.start.line)
return;
if (!caret_set_file (loc.start.file))
return;
diff --git a/src/location.h b/src/location.h
index cbd6f482..24fba608 100644
--- a/src/location.h
+++ b/src/location.h
@@ -33,25 +33,25 @@ typedef struct
/* The name of the file that contains the boundary. */
uniqstr file;
- /* If nonnegative, the (origin-1) line that contains the boundary.
+ /* If positive, the line (starting at 1) that contains the boundary.
If this is INT_MAX, the line number has overflowed.
- Meaningless and not displayed if negative.
+ Meaningless and not displayed if nonpositive.
*/
int line;
- /* If nonnegative, the (origin-1) column just after the boundary.
+ /* If positive, the column (starting at 1) just after the boundary.
This is neither a byte count, nor a character count; it is a
column count. If this is INT_MAX, the column number has
overflowed.
- Meaningless and not displayed if negative.
+ Meaningless and not displayed if nonpositive.
*/
int column;
- /* If nonnegative, (origin-0) bytes number in the current line.
+ /* If nonnegative, the byte number (starting at 0) in the current line.
Never displayed, used when printing error messages with colors to
- know where colors start and ends. */
+ know where colors start and end. */
int byte;
} boundary;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- diagnostics: simplify location handling,
Akim Demaille <=