View Issue Details

IDProjectCategoryView StatusLast Update
0000508LDMud 3.3LPC Compiler/Preprocessorpublic2018-01-29 22:57
ReporterGnomi Assigned Tolars 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformi686OSDebian GNU/LinuxOS Version3.1
Product Version3.3 
Fixed in Version3.3.717 
Summary0000508: There is an off-by-one in the linenumbers in include files using auto-include-strings
DescriptionHi,

consider the following files:

-- oneoff.c ---
#pragma BeginC
#include "oneoff.inc"
#pragma EndC


-- oneoff.inc ---
#pragma IncFile

And an auto-include hook return "#pragma AutoInc-IncFile\n" or "#pragma AutoInc-CFile\n" depending on whether it is the main file or an included file.
These pragmas are just for giving warnings with the current line number.
Compiling oneoff.c gives the following result:

Warning: w/gnomi/oneoff.c (auto include) line 1: Unknown #pragma 'AutoInc-CFile'
Warning: w/gnomi/oneoff.c line 1: Unknown #pragma 'BeginC'
Warning: w/gnomi/oneoff.inc (auto include) line 2: Unknown #pragma 'AutoInc-IncFile'
Warning: w/gnomi/oneoff.inc line 0: Unknown #pragma 'IncFile'
Warning: w/gnomi/oneoff.c line 3: Unknown #pragma 'EndC'

The linenumbers in oneoff.c and its auto include string are correct, but not these from oneoff.inc. The auto include string should start at line 1 not 2, and lineoff.inc should start at line 1 and not 0.

The linenumber within the auto include string is one too high because the #include statement (in handle_preprocessor_statement()) will increment the linenumber after having handled the include stuff, and add_auto_include is not aware of that.

The linenumber within the include file itself is one too low because the linenumbering for include files starts at zero (because the #include will increment it afterwards), for the main file it starts at one. add_auto_include() increments it, to make it correct for include files (because the #incude will now increment the linenumber of the auto include string and not of the include file itself), but the CHAR_EOF handling in yylex1 will decrement it to counteract the incrementation for the main file.

I attached a diff that fixes this. I removed the linenumber adjustment in the CHAR_EOF handling and let add_auto_include() increment the linenumber just once, either before or after starting the auto include string depending on whether we are in the main file or include file.

Greetings,
Gnomi.
TagsNo tags attached.

Activities

2007-08-07 05:40

 

incoffbyone.diff (1,698 bytes)   
Index: trunk/src/lex.c
===================================================================
--- trunk/src/lex.c	(Revision 2314)
+++ trunk/src/lex.c	(Arbeitskopie)
@@ -2592,10 +2592,12 @@
     if (auto_include_string != NULL)
     {
         /* The auto include string is handled like a normal include */
-        current_loc.line++; /* Make sure to restore to line 1 */
+        if (cur_file != NULL)   /* Otherwise we already are at line 1 */
+            current_loc.line++; /* Make sure to restore to line 1 */
         (void)start_new_include(-1, auto_include_string
                                , current_loc.file->name, "auto include", ')');
-        current_loc.line++; /* Make sure to start at line 1 */
+        if (cur_file == NULL)   /* Otherwise #include will increment it */
+            current_loc.line++; /* Make sure to start at line 1 */
     }
 } /* add_auto_include() */
 
@@ -4626,18 +4628,6 @@
                 current_loc = p->loc;
                 if (!was_string_source)
                     current_loc.line++;
-                else
-                {
-                    /* 'string' includes are supposed to be inline
-                     * so correct the line number information to take out
-                     * the assumed newlines.
-                     * This has to be done after store_include_end()
-                     * since that function may remove all line number
-                     * information since the start of the include.
-                     */
-                    current_loc.line -= 1;
-                    store_line_number_backward(1);
-                }
 
                 yyin = p->yyin;
                 saved_char = p->saved_char;
incoffbyone.diff (1,698 bytes)   

lars

2007-11-11 18:39

reporter   ~0000578

Thanks for the patch!

Issue History

Date Modified Username Field Change
2007-08-07 05:40 Gnomi New Issue
2007-08-07 05:40 Gnomi File Added: incoffbyone.diff
2007-11-11 18:39 lars Status new => resolved
2007-11-11 18:39 lars Fixed in Version => 3.3.717
2007-11-11 18:39 lars Resolution open => fixed
2007-11-11 18:39 lars Assigned To => lars
2007-11-11 18:39 lars Note Added: 0000578
2009-04-14 14:14 zesstra Project LDMud => LDMud 3.3
2010-11-16 10:42 lars Source_changeset_attached => ldmud.git master f49af147
2018-01-29 19:59 lars Source_changeset_attached => ldmud.git master f49af147
2018-01-29 22:57 lars Source_changeset_attached => ldmud.git master f49af147