Fossil SCM

Fix overlength source lines in diff.c. Raise limits and fix inappropriate use of memcmp() in mkindex.c.

drh 2016-08-30 15:49 trunk
Commit df80ab0ce93c9ca0c963cf0cc19da5fc07146b74
2 files changed +21 -10 +7 -7
+21 -10
--- src/diff.c
+++ src/diff.c
@@ -113,11 +113,11 @@
113113
int nEditAlloc; /* Space allocated for aEdit[] */
114114
DLine *aFrom; /* File on left side of the diff */
115115
int nFrom; /* Number of lines in aFrom[] */
116116
DLine *aTo; /* File on right side of the diff */
117117
int nTo; /* Number of lines in aTo[] */
118
- int (*same_fn)(const DLine *, const DLine *); /* Function to be used for comparing */
118
+ int (*same_fn)(const DLine*,const DLine*); /* comparison function */
119119
};
120120
121121
/*
122122
** Return an array of DLine objects containing a pointer to the
123123
** start of each line and a hash of that line. The lower
@@ -131,11 +131,16 @@
131131
** too long.
132132
**
133133
** Profiling show that in most cases this routine consumes the bulk of
134134
** the CPU time on a diff.
135135
*/
136
-static DLine *break_into_lines(const char *z, int n, int *pnLine, u64 diffFlags){
136
+static DLine *break_into_lines(
137
+ const char *z,
138
+ int n,
139
+ int *pnLine,
140
+ u64 diffFlags
141
+){
137142
int nLine, i, j, k, s, x;
138143
unsigned int h, h2;
139144
DLine *a;
140145
141146
/* Count the number of lines. Allocate space to hold
@@ -2090,11 +2095,16 @@
20902095
/*
20912096
** The input pParent is the next most recent ancestor of the file
20922097
** being annotated. Do another step of the annotation. Return true
20932098
** if additional annotation is required.
20942099
*/
2095
-static int annotation_step(Annotator *p, Blob *pParent, int iVers, u64 diffFlags){
2100
+static int annotation_step(
2101
+ Annotator *p,
2102
+ Blob *pParent,
2103
+ int iVers,
2104
+ u64 diffFlags
2105
+){
20962106
int i, j;
20972107
int lnTo;
20982108
20992109
/* Prepare the parent file to be diffed */
21002110
p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
@@ -2134,12 +2144,12 @@
21342144
return 0;
21352145
}
21362146
21372147
21382148
/* Annotation flags (any DIFF flag can be used as Annotation flag as well) */
2139
-#define ANN_FILE_VERS (((u64)0x20)<<32) /* Show file vers rather than commit vers */
2140
-#define ANN_FILE_ANCEST (((u64)0x40)<<32) /* Prefer check-ins in the ANCESTOR table */
2149
+#define ANN_FILE_VERS (((u64)0x20)<<32) /* File vers not commit vers */
2150
+#define ANN_FILE_ANCEST (((u64)0x40)<<32) /* Prefer checkins in the ANCESTOR */
21412151
21422152
/*
21432153
** Compute a complete annotation on a file. The file is identified
21442154
** by its filename number (filename.fnid) and check-in (mlink.mid).
21452155
*/
@@ -2443,15 +2453,16 @@
24432453
** the file was last modified. The "annotate" command shows line numbers
24442454
** and omits the username. The "blame" and "praise" commands show the user
24452455
** who made each check-in and omits the line number.
24462456
**
24472457
** Options:
2448
-** --filevers Show file version numbers rather than check-in versions
2449
-** -l|--log List all versions analyzed
2450
-** -n|--limit N Only look backwards in time by N versions
2451
-** -w|--ignore-all-space Ignore white space when comparing lines
2452
-** -Z|--ignore-trailing-space Ignore whitespace at line end
2458
+** --filevers Show file version numbers rather than
2459
+** check-in versions
2460
+** -l|--log List all versions analyzed
2461
+** -n|--limit N Only look backwards in time by N versions
2462
+** -w|--ignore-all-space Ignore white space when comparing lines
2463
+** -Z|--ignore-trailing-space Ignore whitespace at line end
24532464
**
24542465
** See also: info, finfo, timeline
24552466
*/
24562467
void annotate_cmd(void){
24572468
int fnid; /* Filename ID */
24582469
--- src/diff.c
+++ src/diff.c
@@ -113,11 +113,11 @@
113 int nEditAlloc; /* Space allocated for aEdit[] */
114 DLine *aFrom; /* File on left side of the diff */
115 int nFrom; /* Number of lines in aFrom[] */
116 DLine *aTo; /* File on right side of the diff */
117 int nTo; /* Number of lines in aTo[] */
118 int (*same_fn)(const DLine *, const DLine *); /* Function to be used for comparing */
119 };
120
121 /*
122 ** Return an array of DLine objects containing a pointer to the
123 ** start of each line and a hash of that line. The lower
@@ -131,11 +131,16 @@
131 ** too long.
132 **
133 ** Profiling show that in most cases this routine consumes the bulk of
134 ** the CPU time on a diff.
135 */
136 static DLine *break_into_lines(const char *z, int n, int *pnLine, u64 diffFlags){
 
 
 
 
 
137 int nLine, i, j, k, s, x;
138 unsigned int h, h2;
139 DLine *a;
140
141 /* Count the number of lines. Allocate space to hold
@@ -2090,11 +2095,16 @@
2090 /*
2091 ** The input pParent is the next most recent ancestor of the file
2092 ** being annotated. Do another step of the annotation. Return true
2093 ** if additional annotation is required.
2094 */
2095 static int annotation_step(Annotator *p, Blob *pParent, int iVers, u64 diffFlags){
 
 
 
 
 
2096 int i, j;
2097 int lnTo;
2098
2099 /* Prepare the parent file to be diffed */
2100 p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
@@ -2134,12 +2144,12 @@
2134 return 0;
2135 }
2136
2137
2138 /* Annotation flags (any DIFF flag can be used as Annotation flag as well) */
2139 #define ANN_FILE_VERS (((u64)0x20)<<32) /* Show file vers rather than commit vers */
2140 #define ANN_FILE_ANCEST (((u64)0x40)<<32) /* Prefer check-ins in the ANCESTOR table */
2141
2142 /*
2143 ** Compute a complete annotation on a file. The file is identified
2144 ** by its filename number (filename.fnid) and check-in (mlink.mid).
2145 */
@@ -2443,15 +2453,16 @@
2443 ** the file was last modified. The "annotate" command shows line numbers
2444 ** and omits the username. The "blame" and "praise" commands show the user
2445 ** who made each check-in and omits the line number.
2446 **
2447 ** Options:
2448 ** --filevers Show file version numbers rather than check-in versions
2449 ** -l|--log List all versions analyzed
2450 ** -n|--limit N Only look backwards in time by N versions
2451 ** -w|--ignore-all-space Ignore white space when comparing lines
2452 ** -Z|--ignore-trailing-space Ignore whitespace at line end
 
2453 **
2454 ** See also: info, finfo, timeline
2455 */
2456 void annotate_cmd(void){
2457 int fnid; /* Filename ID */
2458
--- src/diff.c
+++ src/diff.c
@@ -113,11 +113,11 @@
113 int nEditAlloc; /* Space allocated for aEdit[] */
114 DLine *aFrom; /* File on left side of the diff */
115 int nFrom; /* Number of lines in aFrom[] */
116 DLine *aTo; /* File on right side of the diff */
117 int nTo; /* Number of lines in aTo[] */
118 int (*same_fn)(const DLine*,const DLine*); /* comparison function */
119 };
120
121 /*
122 ** Return an array of DLine objects containing a pointer to the
123 ** start of each line and a hash of that line. The lower
@@ -131,11 +131,16 @@
131 ** too long.
132 **
133 ** Profiling show that in most cases this routine consumes the bulk of
134 ** the CPU time on a diff.
135 */
136 static DLine *break_into_lines(
137 const char *z,
138 int n,
139 int *pnLine,
140 u64 diffFlags
141 ){
142 int nLine, i, j, k, s, x;
143 unsigned int h, h2;
144 DLine *a;
145
146 /* Count the number of lines. Allocate space to hold
@@ -2090,11 +2095,16 @@
2095 /*
2096 ** The input pParent is the next most recent ancestor of the file
2097 ** being annotated. Do another step of the annotation. Return true
2098 ** if additional annotation is required.
2099 */
2100 static int annotation_step(
2101 Annotator *p,
2102 Blob *pParent,
2103 int iVers,
2104 u64 diffFlags
2105 ){
2106 int i, j;
2107 int lnTo;
2108
2109 /* Prepare the parent file to be diffed */
2110 p->c.aFrom = break_into_lines(blob_str(pParent), blob_size(pParent),
@@ -2134,12 +2144,12 @@
2144 return 0;
2145 }
2146
2147
2148 /* Annotation flags (any DIFF flag can be used as Annotation flag as well) */
2149 #define ANN_FILE_VERS (((u64)0x20)<<32) /* File vers not commit vers */
2150 #define ANN_FILE_ANCEST (((u64)0x40)<<32) /* Prefer checkins in the ANCESTOR */
2151
2152 /*
2153 ** Compute a complete annotation on a file. The file is identified
2154 ** by its filename number (filename.fnid) and check-in (mlink.mid).
2155 */
@@ -2443,15 +2453,16 @@
2453 ** the file was last modified. The "annotate" command shows line numbers
2454 ** and omits the username. The "blame" and "praise" commands show the user
2455 ** who made each check-in and omits the line number.
2456 **
2457 ** Options:
2458 ** --filevers Show file version numbers rather than
2459 ** check-in versions
2460 ** -l|--log List all versions analyzed
2461 ** -n|--limit N Only look backwards in time by N versions
2462 ** -w|--ignore-all-space Ignore white space when comparing lines
2463 ** -Z|--ignore-trailing-space Ignore whitespace at line end
2464 **
2465 ** See also: info, finfo, timeline
2466 */
2467 void annotate_cmd(void){
2468 int fnid; /* Filename ID */
2469
+7 -7
--- src/mkindex.c
+++ src/mkindex.c
@@ -70,16 +70,16 @@
7070
} Entry;
7171
7272
/*
7373
** Maximum number of entries
7474
*/
75
-#define N_ENTRY 500
75
+#define N_ENTRY 5000
7676
7777
/*
7878
** Maximum size of a help message
7979
*/
80
-#define MX_HELP 25000
80
+#define MX_HELP 250000
8181
8282
/*
8383
** Table of entries
8484
*/
8585
Entry aEntry[N_ENTRY];
@@ -91,11 +91,11 @@
9191
int nHelp;
9292
9393
/*
9494
** Most recently encountered #if
9595
*/
96
-char zIf[200];
96
+char zIf[2000];
9797
9898
/*
9999
** How many entries are used
100100
*/
101101
int nUsed;
@@ -154,11 +154,11 @@
154154
int len;
155155
if( zLine[0]!='#' ) return;
156156
for(i=1; isspace(zLine[i]); i++){}
157157
if( zLine[i]==0 ) return;
158158
len = strlen(&zLine[i]);
159
- if( memcmp(&zLine[i],"if",2)==0 ){
159
+ if( strncmp(&zLine[i],"if",2)==0 ){
160160
zIf[0] = '#';
161161
memcpy(&zIf[1], &zLine[i], len+1);
162162
}else if( zLine[i]=='e' ){
163163
zIf[0] = 0;
164164
}
@@ -173,12 +173,12 @@
173173
if( nUsed<=nFixed ) return;
174174
if( strncmp(zLine, "**", 2)==0
175175
&& isspace(zLine[2])
176176
&& strlen(zLine)<sizeof(zHelp)-nHelp-1
177177
&& nUsed>nFixed
178
- && memcmp(zLine,"** COMMAND:",11)!=0
179
- && memcmp(zLine,"** WEBPAGE:",11)!=0
178
+ && strncmp(zLine,"** COMMAND:",11)!=0
179
+ && strncmp(zLine,"** WEBPAGE:",11)!=0
180180
){
181181
if( zLine[2]=='\n' ){
182182
zHelp[nHelp++] = '\n';
183183
}else{
184184
if( strncmp(&zLine[3], "Usage: ", 6)==0 ) nHelp = 0;
@@ -287,11 +287,11 @@
287287
int cmdFlags = (1==aEntry[i].eType) ? 0x01 : 0x08;
288288
if( 0x01==cmdFlags ){
289289
if( z[n-1]=='*' ){
290290
n--;
291291
cmdFlags = 0x02;
292
- }else if( memcmp(z, "test-", 5)==0 ){
292
+ }else if( strncmp(z, "test-", 5)==0 ){
293293
cmdFlags = 0x04;
294294
}
295295
}
296296
if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
297297
printf(" { \"%s%.*s\",%*s %s,%*s %d },\n",
298298
--- src/mkindex.c
+++ src/mkindex.c
@@ -70,16 +70,16 @@
70 } Entry;
71
72 /*
73 ** Maximum number of entries
74 */
75 #define N_ENTRY 500
76
77 /*
78 ** Maximum size of a help message
79 */
80 #define MX_HELP 25000
81
82 /*
83 ** Table of entries
84 */
85 Entry aEntry[N_ENTRY];
@@ -91,11 +91,11 @@
91 int nHelp;
92
93 /*
94 ** Most recently encountered #if
95 */
96 char zIf[200];
97
98 /*
99 ** How many entries are used
100 */
101 int nUsed;
@@ -154,11 +154,11 @@
154 int len;
155 if( zLine[0]!='#' ) return;
156 for(i=1; isspace(zLine[i]); i++){}
157 if( zLine[i]==0 ) return;
158 len = strlen(&zLine[i]);
159 if( memcmp(&zLine[i],"if",2)==0 ){
160 zIf[0] = '#';
161 memcpy(&zIf[1], &zLine[i], len+1);
162 }else if( zLine[i]=='e' ){
163 zIf[0] = 0;
164 }
@@ -173,12 +173,12 @@
173 if( nUsed<=nFixed ) return;
174 if( strncmp(zLine, "**", 2)==0
175 && isspace(zLine[2])
176 && strlen(zLine)<sizeof(zHelp)-nHelp-1
177 && nUsed>nFixed
178 && memcmp(zLine,"** COMMAND:",11)!=0
179 && memcmp(zLine,"** WEBPAGE:",11)!=0
180 ){
181 if( zLine[2]=='\n' ){
182 zHelp[nHelp++] = '\n';
183 }else{
184 if( strncmp(&zLine[3], "Usage: ", 6)==0 ) nHelp = 0;
@@ -287,11 +287,11 @@
287 int cmdFlags = (1==aEntry[i].eType) ? 0x01 : 0x08;
288 if( 0x01==cmdFlags ){
289 if( z[n-1]=='*' ){
290 n--;
291 cmdFlags = 0x02;
292 }else if( memcmp(z, "test-", 5)==0 ){
293 cmdFlags = 0x04;
294 }
295 }
296 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
297 printf(" { \"%s%.*s\",%*s %s,%*s %d },\n",
298
--- src/mkindex.c
+++ src/mkindex.c
@@ -70,16 +70,16 @@
70 } Entry;
71
72 /*
73 ** Maximum number of entries
74 */
75 #define N_ENTRY 5000
76
77 /*
78 ** Maximum size of a help message
79 */
80 #define MX_HELP 250000
81
82 /*
83 ** Table of entries
84 */
85 Entry aEntry[N_ENTRY];
@@ -91,11 +91,11 @@
91 int nHelp;
92
93 /*
94 ** Most recently encountered #if
95 */
96 char zIf[2000];
97
98 /*
99 ** How many entries are used
100 */
101 int nUsed;
@@ -154,11 +154,11 @@
154 int len;
155 if( zLine[0]!='#' ) return;
156 for(i=1; isspace(zLine[i]); i++){}
157 if( zLine[i]==0 ) return;
158 len = strlen(&zLine[i]);
159 if( strncmp(&zLine[i],"if",2)==0 ){
160 zIf[0] = '#';
161 memcpy(&zIf[1], &zLine[i], len+1);
162 }else if( zLine[i]=='e' ){
163 zIf[0] = 0;
164 }
@@ -173,12 +173,12 @@
173 if( nUsed<=nFixed ) return;
174 if( strncmp(zLine, "**", 2)==0
175 && isspace(zLine[2])
176 && strlen(zLine)<sizeof(zHelp)-nHelp-1
177 && nUsed>nFixed
178 && strncmp(zLine,"** COMMAND:",11)!=0
179 && strncmp(zLine,"** WEBPAGE:",11)!=0
180 ){
181 if( zLine[2]=='\n' ){
182 zHelp[nHelp++] = '\n';
183 }else{
184 if( strncmp(&zLine[3], "Usage: ", 6)==0 ) nHelp = 0;
@@ -287,11 +287,11 @@
287 int cmdFlags = (1==aEntry[i].eType) ? 0x01 : 0x08;
288 if( 0x01==cmdFlags ){
289 if( z[n-1]=='*' ){
290 n--;
291 cmdFlags = 0x02;
292 }else if( strncmp(z, "test-", 5)==0 ){
293 cmdFlags = 0x04;
294 }
295 }
296 if( aEntry[i].zIf ) printf("%s", aEntry[i].zIf);
297 printf(" { \"%s%.*s\",%*s %s,%*s %d },\n",
298

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button