Fossil

Check-in [c67d54010d]
Login

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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c67d54010d5b3e1ce3383c478058ecb534ed299b51c951a6b140965bb0a30d6f
User & Date: wyoung 2022-02-28 20:35:57.684
Original Comment: Simplified an overly-clever test for a file size being an even multiple of 512 bytes. [https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGIMwCspK4AMngMmAByPgBGmMQg0gAOqAqETgwe3r7%2BQSlpjgJhEdEscQnSdpgOGUIETMQEWT5%2BgbaY9oUMdQ0ExVGx8Ym29Y3NOW0Ko33hA2VDkgCUtqhexMjsHAD0WwDUACoAnkmYu4erxLtoWLsI8ZikuyS7tKhM6LuGu5iqrEn0ADoTBoAILhAi7PAKAD6AS4Zgg4N2DB8i12JgA7FZQeYAMx4Ki7EHo0G7Mm7YiYAhrBi7CAoljoswANl2GlUXCoVDRYDAJlxABE2fzsSC8R0lMDieTKdTiLT6T4mQFdnCzDy%2BYLhbjReKGPgqFLMQKOMtaJwArw/BwtKRUJw3NZrLsFBcNkzcTxSARNKblgBrEABDT6TiSK2%2Bu2cXgKEAhn0202kOCwGCIFCoFhJOjxciUNBZnMJYBceF8OgEeKxiAxSMxcINQ6cL0FtiCADyDFoTcTpCwLEMwHEvfwlJqADdMLHez9ql5K83eOCOpHaHgYsRGx4sJGCMQ8CxF8sqAZgAoAGp4TAAd3bJ2tXv4ghEYnYUhkgkUKnUvd0Zn0g4oE6lj6OusaQMsqBJF004ALQCiCMYdNUXQuPq4x%2BGWoSzKU5QSFwpD5OkAgYRI/5EV0/S4UMpbtJ0tTTKRZZVDUAg9I0VGDAktFTL0TH/rxHE4Vx%2BHLK6awbHoe6YJsPBmhaEa9vaHCqAAHMysHMpIuzAMgyC7KWAJmHSjqWNYjy4IQzx4gRuweIW9CXHi6q8AmWiLAGQYhuaHDhqQh7BqQ1q2spMZxt6vrLCm6YFtmjl5hAsVFiAJZljQtCVsQ1a1r29bMMQPYtpmbYEJ23aRv2g7Drao4oXgk7Tras7IPOslLoIK69muG5bhgmy2nuB5Hnwp4Xlet73ouH7CKI4jvk%2B8hKGoka6ARBhGEBZkgd14EQJB0EZHBAoWEh9HOBArhMcE%2BqcfM3GEakxGZJ4LR6BRGS3XhBEsV07FNC9OTfchrHdNMn00SMfEA5hkNCSUIlcGJbpvt6lJtfJHCWkFkbKWpGlaTpekGVwRkmcBNi7JZRBOWYnqPPZcXxB6iOuZFyx3O8Qx7aGvm8AFIbBbwoW2OFbl%2BqQgaBT5uKKSF0YRYmHk82YstC/LYtK5OWUZIkQA | 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: 491b986d0d 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: c67d54010d 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 [/info/bd7f2727ba25912e | an omnibus commit] for obscure reasons, it causes some valid clone operations to fail, as originally reported [forum:/forumpost/16880a28aad1a868 | on the forum]. check-in: 4a2d0e7878 user: wyoung tags: trunk
Changes
Unified Diff 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);