Fossil

Check-in [c67d5401]
Login

Check-in [c67d5401]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Simplified an overly-clever test for a file size being an even multiple of 512 bytes. Compiler Explorer says GCC 11 generates the same code both ways, at least, and it isn't in a CPU-critical code path anyway. Also added a comment referring to this new, simplified code, to prevent a recurrence of the problem fixed by the prior commit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c67d54010d5b3e1ce3383c478058ecb534ed299b51c951a6b140965bb0a30d6f
User & Date: wyoung 2022-02-28 20:35:57
Original Comment: Simplified an overly-clever test for a file size being an even multiple of 512 bytes. Godbolt says GCC 11 generates the same code both ways, at least, and it isn't in a CPU-critical code path anyway. Also added a comment referring to this new, simplified code, to prevent a recurrence of the problem fixed by the prior commit.
Context
2022-02-28
20:49
Since checkin [d8c32ebdff], file_fullexename() function is supported windows, remove comment saying otherwize. (no code change) ... (check-in: 491b986d user: mgagnon tags: trunk)
20:35
Simplified an overly-clever test for a file size being an even multiple of 512 bytes. Compiler Explorer says GCC 11 generates the same code both ways, at least, and it isn't in a CPU-critical code path anyway. Also added a comment referring to this new, simplified code, to prevent a recurrence of the problem fixed by the prior commit. ... (check-in: c67d5401 user: wyoung tags: trunk)
19:23
Reverted a check for the repository size being an even multiple of 512 bytes as a test for validity. Introduced in an omnibus commit for obscure reasons, it causes some valid clone operations to fail, as originally reported on the forum. ... (check-in: 4a2d0e78 user: wyoung tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/db.c.

2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
  i64 sz;
  int rc;
  int res = 0;
  sqlite3_stmt *pStmt = 0;

  sz = file_size(zDbName, ExtFILE);
  if( sz<16834 ) return 0;
  if( sz & 0x1ff ) return 0;
  rc = sqlite3_open(zDbName, &db);
  if( rc ) goto is_repo_end;
  rc = sqlite3_prepare_v2(db, 
       "SELECT count(*) FROM sqlite_schema"
       " WHERE name COLLATE nocase IN"
       "('blob','delta','rcvfrom','user','config','mlink','plink');",
       -1, &pStmt, 0);







|







2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
  i64 sz;
  int rc;
  int res = 0;
  sqlite3_stmt *pStmt = 0;

  sz = file_size(zDbName, ExtFILE);
  if( sz<16834 ) return 0;
  if( sz%512 ) return 0;
  rc = sqlite3_open(zDbName, &db);
  if( rc ) goto is_repo_end;
  rc = sqlite3_prepare_v2(db, 
       "SELECT count(*) FROM sqlite_schema"
       " WHERE name COLLATE nocase IN"
       "('blob','delta','rcvfrom','user','config','mlink','plink');",
       -1, &pStmt, 0);
2186
2187
2188
2189
2190
2191
2192



2193
2194
2195
2196
2197
2198
2199
    if( g.localOpen ){
      zDbName = db_repository_filename();
    }
    if( zDbName==0 ){
      db_err("unable to find the name of a repository database");
    }
  }



  if( file_access(zDbName, R_OK) || file_size(zDbName, ExtFILE)<1024 ){
    if( file_access(zDbName, F_OK) ){
#ifdef FOSSIL_ENABLE_JSON
      g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
#endif
      fossil_fatal("repository does not exist or"
                   " is in an unreadable directory: %s", zDbName);







>
>
>







2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
    if( g.localOpen ){
      zDbName = db_repository_filename();
    }
    if( zDbName==0 ){
      db_err("unable to find the name of a repository database");
    }
  }
  /* Don't change the file size test to call db_looks_like_a_repository()
   * or copy code from it. The sz%512 bit in particular is wrong for the
   * apndvfs case in db_open() above. */
  if( file_access(zDbName, R_OK) || file_size(zDbName, ExtFILE)<1024 ){
    if( file_access(zDbName, F_OK) ){
#ifdef FOSSIL_ENABLE_JSON
      g.json.resultCode = FSL_JSON_E_DB_NOT_FOUND;
#endif
      fossil_fatal("repository does not exist or"
                   " is in an unreadable directory: %s", zDbName);