Fossil SCM

Rid the code of the legacy UUID_SIZE macro. Replace it everywhere with either HNAME_MAX or HNAME_LEN_SHA1 or HNAME_LEN_K256, as appropriate.

drh 2018-03-07 19:46 trunk
Commit 323299cb5605ed79ea3d13a64800ff22ac1ec4613e7048c7ba7d98920f7c4fb9
+1 -1
--- src/graph.c
+++ src/graph.c
@@ -37,11 +37,11 @@
3737
int rid; /* The rid for the check-in */
3838
i8 nParent; /* Number of parents. -1 for technote lines */
3939
int *aParent; /* Array of parents. 0 element is primary .*/
4040
char *zBranch; /* Branch name */
4141
char *zBgClr; /* Background Color */
42
- char zUuid[41]; /* Check-in for file ID */
42
+ char zUuid[HNAME_MAX+1]; /* Check-in for file ID */
4343
4444
GraphRow *pNext; /* Next row down in the list of all rows */
4545
GraphRow *pPrev; /* Previous row */
4646
4747
int idx; /* Row index. First is 1. 0 used for "none" */
4848
--- src/graph.c
+++ src/graph.c
@@ -37,11 +37,11 @@
37 int rid; /* The rid for the check-in */
38 i8 nParent; /* Number of parents. -1 for technote lines */
39 int *aParent; /* Array of parents. 0 element is primary .*/
40 char *zBranch; /* Branch name */
41 char *zBgClr; /* Background Color */
42 char zUuid[41]; /* Check-in for file ID */
43
44 GraphRow *pNext; /* Next row down in the list of all rows */
45 GraphRow *pPrev; /* Previous row */
46
47 int idx; /* Row index. First is 1. 0 used for "none" */
48
--- src/graph.c
+++ src/graph.c
@@ -37,11 +37,11 @@
37 int rid; /* The rid for the check-in */
38 i8 nParent; /* Number of parents. -1 for technote lines */
39 int *aParent; /* Array of parents. 0 element is primary .*/
40 char *zBranch; /* Branch name */
41 char *zBgClr; /* Background Color */
42 char zUuid[HNAME_MAX+1]; /* Check-in for file ID */
43
44 GraphRow *pNext; /* Next row down in the list of all rows */
45 GraphRow *pPrev; /* Previous row */
46
47 int idx; /* Row index. First is 1. 0 used for "none" */
48
+3 -4
--- src/info.c
+++ src/info.c
@@ -1464,11 +1464,10 @@
14641464
" ORDER BY mtime DESC /*sort*/",
14651465
rid
14661466
);
14671467
while( db_step(&q)==SQLITE_ROW ){
14681468
const char *zTarget = db_column_text(&q, 0);
1469
- int nTarget = db_column_bytes(&q, 0);
14701469
const char *zFilename = db_column_text(&q, 1);
14711470
const char *zDate = db_column_text(&q, 2);
14721471
const char *zUser = db_column_text(&q, 3);
14731472
/* const char *zSrc = db_column_text(&q, 4); */
14741473
if( cnt>0 ){
@@ -1475,11 +1474,11 @@
14751474
@ Also attachment "%h(zFilename)" to
14761475
}else{
14771476
@ Attachment "%h(zFilename)" to
14781477
}
14791478
objType |= OBJTYPE_ATTACHMENT;
1480
- if( nTarget==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1479
+ if( fossil_is_uuid(zTarget) ){
14811480
if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
14821481
zTarget)
14831482
){
14841483
if( g.perm.Hyperlink && g.anon.RdTkt ){
14851484
@ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
@@ -2185,11 +2184,11 @@
21852184
*/
21862185
void tinfo_page(void){
21872186
int rid;
21882187
char *zDate;
21892188
const char *zUuid;
2190
- char zTktName[UUID_SIZE+1];
2189
+ char zTktName[HNAME_MAX+1];
21912190
Manifest *pTktChng;
21922191
int modPending;
21932192
const char *zModAction;
21942193
char *zTktTitle;
21952194
login_check_credentials();
@@ -2206,11 +2205,11 @@
22062205
}
22072206
}
22082207
pTktChng = manifest_get(rid, CFTYPE_TICKET, 0);
22092208
if( pTktChng==0 ) fossil_redirect_home();
22102209
zDate = db_text(0, "SELECT datetime(%.12f)", pTktChng->rDate);
2211
- memcpy(zTktName, pTktChng->zTicketUuid, UUID_SIZE+1);
2210
+ sqlite3_snprintf(sizeof(zTktName), zTktName, "%s", pTktChng->zTicketUuid);
22122211
if( g.perm.ModTkt && (zModAction = P("modaction"))!=0 ){
22132212
if( strcmp(zModAction,"delete")==0 ){
22142213
moderation_disapprove(rid);
22152214
/*
22162215
** Next, check if the ticket still exists; if not, we cannot
22172216
--- src/info.c
+++ src/info.c
@@ -1464,11 +1464,10 @@
1464 " ORDER BY mtime DESC /*sort*/",
1465 rid
1466 );
1467 while( db_step(&q)==SQLITE_ROW ){
1468 const char *zTarget = db_column_text(&q, 0);
1469 int nTarget = db_column_bytes(&q, 0);
1470 const char *zFilename = db_column_text(&q, 1);
1471 const char *zDate = db_column_text(&q, 2);
1472 const char *zUser = db_column_text(&q, 3);
1473 /* const char *zSrc = db_column_text(&q, 4); */
1474 if( cnt>0 ){
@@ -1475,11 +1474,11 @@
1475 @ Also attachment "%h(zFilename)" to
1476 }else{
1477 @ Attachment "%h(zFilename)" to
1478 }
1479 objType |= OBJTYPE_ATTACHMENT;
1480 if( nTarget==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1481 if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
1482 zTarget)
1483 ){
1484 if( g.perm.Hyperlink && g.anon.RdTkt ){
1485 @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
@@ -2185,11 +2184,11 @@
2185 */
2186 void tinfo_page(void){
2187 int rid;
2188 char *zDate;
2189 const char *zUuid;
2190 char zTktName[UUID_SIZE+1];
2191 Manifest *pTktChng;
2192 int modPending;
2193 const char *zModAction;
2194 char *zTktTitle;
2195 login_check_credentials();
@@ -2206,11 +2205,11 @@
2206 }
2207 }
2208 pTktChng = manifest_get(rid, CFTYPE_TICKET, 0);
2209 if( pTktChng==0 ) fossil_redirect_home();
2210 zDate = db_text(0, "SELECT datetime(%.12f)", pTktChng->rDate);
2211 memcpy(zTktName, pTktChng->zTicketUuid, UUID_SIZE+1);
2212 if( g.perm.ModTkt && (zModAction = P("modaction"))!=0 ){
2213 if( strcmp(zModAction,"delete")==0 ){
2214 moderation_disapprove(rid);
2215 /*
2216 ** Next, check if the ticket still exists; if not, we cannot
2217
--- src/info.c
+++ src/info.c
@@ -1464,11 +1464,10 @@
1464 " ORDER BY mtime DESC /*sort*/",
1465 rid
1466 );
1467 while( db_step(&q)==SQLITE_ROW ){
1468 const char *zTarget = db_column_text(&q, 0);
 
1469 const char *zFilename = db_column_text(&q, 1);
1470 const char *zDate = db_column_text(&q, 2);
1471 const char *zUser = db_column_text(&q, 3);
1472 /* const char *zSrc = db_column_text(&q, 4); */
1473 if( cnt>0 ){
@@ -1475,11 +1474,11 @@
1474 @ Also attachment "%h(zFilename)" to
1475 }else{
1476 @ Attachment "%h(zFilename)" to
1477 }
1478 objType |= OBJTYPE_ATTACHMENT;
1479 if( fossil_is_uuid(zTarget) ){
1480 if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
1481 zTarget)
1482 ){
1483 if( g.perm.Hyperlink && g.anon.RdTkt ){
1484 @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
@@ -2185,11 +2184,11 @@
2184 */
2185 void tinfo_page(void){
2186 int rid;
2187 char *zDate;
2188 const char *zUuid;
2189 char zTktName[HNAME_MAX+1];
2190 Manifest *pTktChng;
2191 int modPending;
2192 const char *zModAction;
2193 char *zTktTitle;
2194 login_check_credentials();
@@ -2206,11 +2205,11 @@
2205 }
2206 }
2207 pTktChng = manifest_get(rid, CFTYPE_TICKET, 0);
2208 if( pTktChng==0 ) fossil_redirect_home();
2209 zDate = db_text(0, "SELECT datetime(%.12f)", pTktChng->rDate);
2210 sqlite3_snprintf(sizeof(zTktName), zTktName, "%s", pTktChng->zTicketUuid);
2211 if( g.perm.ModTkt && (zModAction = P("modaction"))!=0 ){
2212 if( strcmp(zModAction,"delete")==0 ){
2213 moderation_disapprove(rid);
2214 /*
2215 ** Next, check if the ticket still exists; if not, we cannot
2216
-10
--- src/main.c
+++ src/main.c
@@ -49,20 +49,10 @@
4949
#ifdef FOSSIL_ENABLE_JSON
5050
# include "cson_amalgamation.h" /* JSON API. */
5151
# include "json_detail.h"
5252
#endif
5353
54
-/*
55
-** Size of a UUID in characters. A UUID is a randomly generated
56
-** lower-case hexadecimal number used to identify tickets.
57
-**
58
-** In Fossil 1.x, UUID also referred to a SHA1 artifact hash. But that
59
-** usage is now obsolete. The term UUID should now mean only a very large
60
-** random number used as a unique identifier for tickets or other objects.
61
-*/
62
-#define UUID_SIZE 40
63
-
6454
/*
6555
** Maximum number of auxiliary parameters on reports
6656
*/
6757
#define MX_AUX 5
6858
6959
--- src/main.c
+++ src/main.c
@@ -49,20 +49,10 @@
49 #ifdef FOSSIL_ENABLE_JSON
50 # include "cson_amalgamation.h" /* JSON API. */
51 # include "json_detail.h"
52 #endif
53
54 /*
55 ** Size of a UUID in characters. A UUID is a randomly generated
56 ** lower-case hexadecimal number used to identify tickets.
57 **
58 ** In Fossil 1.x, UUID also referred to a SHA1 artifact hash. But that
59 ** usage is now obsolete. The term UUID should now mean only a very large
60 ** random number used as a unique identifier for tickets or other objects.
61 */
62 #define UUID_SIZE 40
63
64 /*
65 ** Maximum number of auxiliary parameters on reports
66 */
67 #define MX_AUX 5
68
69
--- src/main.c
+++ src/main.c
@@ -49,20 +49,10 @@
49 #ifdef FOSSIL_ENABLE_JSON
50 # include "cson_amalgamation.h" /* JSON API. */
51 # include "json_detail.h"
52 #endif
53
 
 
 
 
 
 
 
 
 
 
54 /*
55 ** Maximum number of auxiliary parameters on reports
56 */
57 #define MX_AUX 5
58
59
+2 -2
--- src/manifest.c
+++ src/manifest.c
@@ -607,12 +607,12 @@
607607
** is amending.
608608
*/
609609
case 'K': {
610610
if( p->zTicketUuid!=0 ) SYNTAX("more than one K-card");
611611
p->zTicketUuid = next_token(&x, &sz);
612
- if( sz!=UUID_SIZE ) SYNTAX("K-card UUID is the wrong size");
613
- if( !validate16(p->zTicketUuid, UUID_SIZE) ){
612
+ if( sz!=HNAME_LEN_SHA1 ) SYNTAX("K-card UUID is the wrong size");
613
+ if( !validate16(p->zTicketUuid, sz) ){
614614
SYNTAX("invalid K-card UUID");
615615
}
616616
break;
617617
}
618618
619619
--- src/manifest.c
+++ src/manifest.c
@@ -607,12 +607,12 @@
607 ** is amending.
608 */
609 case 'K': {
610 if( p->zTicketUuid!=0 ) SYNTAX("more than one K-card");
611 p->zTicketUuid = next_token(&x, &sz);
612 if( sz!=UUID_SIZE ) SYNTAX("K-card UUID is the wrong size");
613 if( !validate16(p->zTicketUuid, UUID_SIZE) ){
614 SYNTAX("invalid K-card UUID");
615 }
616 break;
617 }
618
619
--- src/manifest.c
+++ src/manifest.c
@@ -607,12 +607,12 @@
607 ** is amending.
608 */
609 case 'K': {
610 if( p->zTicketUuid!=0 ) SYNTAX("more than one K-card");
611 p->zTicketUuid = next_token(&x, &sz);
612 if( sz!=HNAME_LEN_SHA1 ) SYNTAX("K-card UUID is the wrong size");
613 if( !validate16(p->zTicketUuid, sz) ){
614 SYNTAX("invalid K-card UUID");
615 }
616 break;
617 }
618
619
+1 -1
--- src/tkt.c
+++ src/tkt.c
@@ -747,11 +747,11 @@
747747
zName = P("name");
748748
if( P("cancel") ){
749749
cgi_redirectf("tktview?name=%T", zName);
750750
}
751751
style_header("Edit Ticket");
752
- if( zName==0 || (nName = strlen(zName))<4 || nName>UUID_SIZE
752
+ if( zName==0 || (nName = strlen(zName))<4 || nName>HNAME_LEN_SHA1
753753
|| !validate16(zName,nName) ){
754754
@ <span class="tktError">Not a valid ticket id: "%h(zName)"</span>
755755
style_footer();
756756
return;
757757
}
758758
--- src/tkt.c
+++ src/tkt.c
@@ -747,11 +747,11 @@
747 zName = P("name");
748 if( P("cancel") ){
749 cgi_redirectf("tktview?name=%T", zName);
750 }
751 style_header("Edit Ticket");
752 if( zName==0 || (nName = strlen(zName))<4 || nName>UUID_SIZE
753 || !validate16(zName,nName) ){
754 @ <span class="tktError">Not a valid ticket id: "%h(zName)"</span>
755 style_footer();
756 return;
757 }
758
--- src/tkt.c
+++ src/tkt.c
@@ -747,11 +747,11 @@
747 zName = P("name");
748 if( P("cancel") ){
749 cgi_redirectf("tktview?name=%T", zName);
750 }
751 style_header("Edit Ticket");
752 if( zName==0 || (nName = strlen(zName))<4 || nName>HNAME_LEN_SHA1
753 || !validate16(zName,nName) ){
754 @ <span class="tktError">Not a valid ticket id: "%h(zName)"</span>
755 style_footer();
756 return;
757 }
758
+4 -5
--- src/util.c
+++ src/util.c
@@ -376,17 +376,16 @@
376376
return fcntl(fd, F_GETFL)!=(-1) || errno!=EBADF;
377377
#endif
378378
}
379379
380380
/*
381
-** Returns TRUE if zSym is exactly UUID_SIZE bytes long and contains
382
-** only lower-case ASCII hexadecimal values.
381
+** Returns TRUE if zSym is exactly HNAME_LEN_SHA1 or HNAME_LEN_K256
382
+** bytes long and contains only lower-case ASCII hexadecimal values.
383383
*/
384384
int fossil_is_uuid(const char *zSym){
385
- return zSym
386
- && (UUID_SIZE==strlen(zSym))
387
- && validate16(zSym, UUID_SIZE);
385
+ int sz = zSym ? (int)strlen(zSym) : 0;
386
+ return (HNAME_LEN_SHA1==sz || HNAME_LEN_K256==sz) && validate16(zSym, sz);
388387
}
389388
390389
/*
391390
** Return true if the input string is NULL or all whitespace.
392391
** Return false if the input string contains text.
393392
--- src/util.c
+++ src/util.c
@@ -376,17 +376,16 @@
376 return fcntl(fd, F_GETFL)!=(-1) || errno!=EBADF;
377 #endif
378 }
379
380 /*
381 ** Returns TRUE if zSym is exactly UUID_SIZE bytes long and contains
382 ** only lower-case ASCII hexadecimal values.
383 */
384 int fossil_is_uuid(const char *zSym){
385 return zSym
386 && (UUID_SIZE==strlen(zSym))
387 && validate16(zSym, UUID_SIZE);
388 }
389
390 /*
391 ** Return true if the input string is NULL or all whitespace.
392 ** Return false if the input string contains text.
393
--- src/util.c
+++ src/util.c
@@ -376,17 +376,16 @@
376 return fcntl(fd, F_GETFL)!=(-1) || errno!=EBADF;
377 #endif
378 }
379
380 /*
381 ** Returns TRUE if zSym is exactly HNAME_LEN_SHA1 or HNAME_LEN_K256
382 ** bytes long and contains only lower-case ASCII hexadecimal values.
383 */
384 int fossil_is_uuid(const char *zSym){
385 int sz = zSym ? (int)strlen(zSym) : 0;
386 return (HNAME_LEN_SHA1==sz || HNAME_LEN_K256==sz) && validate16(zSym, sz);
 
387 }
388
389 /*
390 ** Return true if the input string is NULL or all whitespace.
391 ** Return false if the input string contains text.
392
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1110,12 +1110,12 @@
11101110
){
11111111
static Stmt q;
11121112
static int once = 1;
11131113
int n;
11141114
int rc;
1115
- char zLower[UUID_SIZE+1];
1116
- char zUpper[UUID_SIZE+1];
1115
+ char zLower[HNAME_MAX+1];
1116
+ char zUpper[HNAME_MAX+1];
11171117
n = strlen(zTarget);
11181118
memcpy(zLower, zTarget, n+1);
11191119
canonical16(zLower, n+1);
11201120
memcpy(zUpper, zLower, n+1);
11211121
zUpper[n-1]++;
@@ -1218,11 +1218,11 @@
12181218
blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
12191219
}else if( zTarget[0]=='#' ){
12201220
blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
12211221
}else if( is_valid_hname(zTarget) ){
12221222
int isClosed = 0;
1223
- if( strlen(zTarget)<=UUID_SIZE && is_ticket(zTarget, &isClosed) ){
1223
+ if( strlen(zTarget)<=HNAME_MAX && is_ticket(zTarget, &isClosed) ){
12241224
/* Special display processing for tickets. Display the hyperlink
12251225
** as crossed out if the ticket is closed.
12261226
*/
12271227
if( isClosed ){
12281228
if( g.perm.Hyperlink ){
@@ -1831,11 +1831,11 @@
18311831
}
18321832
switch( tokenType ){
18331833
case TOKEN_LINK: {
18341834
char *zTarget;
18351835
int i, c;
1836
- char zLink[42];
1836
+ char zLink[HNAME_MAX+4];
18371837
18381838
zTarget = &z[1];
18391839
for(i=0; zTarget[i] && zTarget[i]!='|' && zTarget[i]!=']'; i++){}
18401840
while(i>1 && zTarget[i-1]==' '){ i--; }
18411841
c = zTarget[i];
18421842
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1110,12 +1110,12 @@
1110 ){
1111 static Stmt q;
1112 static int once = 1;
1113 int n;
1114 int rc;
1115 char zLower[UUID_SIZE+1];
1116 char zUpper[UUID_SIZE+1];
1117 n = strlen(zTarget);
1118 memcpy(zLower, zTarget, n+1);
1119 canonical16(zLower, n+1);
1120 memcpy(zUpper, zLower, n+1);
1121 zUpper[n-1]++;
@@ -1218,11 +1218,11 @@
1218 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1219 }else if( zTarget[0]=='#' ){
1220 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1221 }else if( is_valid_hname(zTarget) ){
1222 int isClosed = 0;
1223 if( strlen(zTarget)<=UUID_SIZE && is_ticket(zTarget, &isClosed) ){
1224 /* Special display processing for tickets. Display the hyperlink
1225 ** as crossed out if the ticket is closed.
1226 */
1227 if( isClosed ){
1228 if( g.perm.Hyperlink ){
@@ -1831,11 +1831,11 @@
1831 }
1832 switch( tokenType ){
1833 case TOKEN_LINK: {
1834 char *zTarget;
1835 int i, c;
1836 char zLink[42];
1837
1838 zTarget = &z[1];
1839 for(i=0; zTarget[i] && zTarget[i]!='|' && zTarget[i]!=']'; i++){}
1840 while(i>1 && zTarget[i-1]==' '){ i--; }
1841 c = zTarget[i];
1842
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1110,12 +1110,12 @@
1110 ){
1111 static Stmt q;
1112 static int once = 1;
1113 int n;
1114 int rc;
1115 char zLower[HNAME_MAX+1];
1116 char zUpper[HNAME_MAX+1];
1117 n = strlen(zTarget);
1118 memcpy(zLower, zTarget, n+1);
1119 canonical16(zLower, n+1);
1120 memcpy(zUpper, zLower, n+1);
1121 zUpper[n-1]++;
@@ -1218,11 +1218,11 @@
1218 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1219 }else if( zTarget[0]=='#' ){
1220 blob_appendf(p->pOut, "<a href=\"%h\">", zTarget);
1221 }else if( is_valid_hname(zTarget) ){
1222 int isClosed = 0;
1223 if( strlen(zTarget)<=HNAME_MAX && is_ticket(zTarget, &isClosed) ){
1224 /* Special display processing for tickets. Display the hyperlink
1225 ** as crossed out if the ticket is closed.
1226 */
1227 if( isClosed ){
1228 if( g.perm.Hyperlink ){
@@ -1831,11 +1831,11 @@
1831 }
1832 switch( tokenType ){
1833 case TOKEN_LINK: {
1834 char *zTarget;
1835 int i, c;
1836 char zLink[HNAME_MAX+4];
1837
1838 zTarget = &z[1];
1839 for(i=0; zTarget[i] && zTarget[i]!='|' && zTarget[i]!=']'; i++){}
1840 while(i>1 && zTarget[i-1]==' '){ i--; }
1841 c = zTarget[i];
1842

Keyboard Shortcuts

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