FreeBSD/contrib/subversion/subversion/libsvn_fs_x/verify.c
/* Verify that the next SIZE bytes read from FILE are NUL.  SIZE must not
 * exceed STREAM_THRESHOLD.  Use SCRATCH_POOL for temporary allocations.
 */
Verify that the next SIZE bytes read from FILE are NUL.  SIZE must not
exceed STREAM_THRESHOLD.  Use SCRATCH_POOL for temporary allocations.
Verify that the next SIZE bytes read from FILE are NUL . SIZE must not exceed STREAM_THRESHOLD . Use SCRATCH_POOL for temporary allocations .
static svn_error_t *
expect_buffer_nul(apr_file_t *file,
                  apr_off_t size,
                  apr_pool_t *scratch_pool)
{
  union
  {
    unsigned char buffer[STREAM_THRESHOLD];
    apr_uint64_t chunks[STREAM_THRESHOLD / sizeof(apr_uint64_t)];
  } data;
  apr_size_t i;
  SVN_ERR_ASSERT(size <= STREAM_THRESHOLD);
  data.chunks[(size - 1)/ sizeof(apr_uint64_t)] = 0;
  SVN_ERR(svn_io_file_read_full2(file, data.buffer, size, NULL, NULL,
                                 scratch_pool));
  for (i = 0; i < size / sizeof(apr_uint64_t); ++i)
    if (data.chunks[i] != 0)
      break;
  for (i *= sizeof(apr_uint64_t); i < size; ++i)
    if (data.buffer[i] != 0)
      {
        const char *file_name;
        apr_off_t offset;
        SVN_ERR(svn_io_file_name_get(&file_name, file, scratch_pool));
        SVN_ERR(svn_fs_x__get_file_offset(&offset, file, scratch_pool));
        offset -= size - i;
        return svn_error_createf(SVN_ERR_FS_CORRUPT, NULL,
                                 _("Empty section in file %s contains "
                                   "non-NUL data at offset %s"),
                                 file_name,
                                 apr_off_t_toa(scratch_pool, offset));
      }
  return SVN_NO_ERROR;
}
static svn_error_t * expect_buffer_nul ( apr_file_t * file , apr_off_t size , apr_pool_t * scratch_pool ) { union { unsigned char buffer [ STREAM_THRESHOLD ] ; apr_uint64_t chunks [ STREAM_THRESHOLD / sizeof ( apr_uint64_t ) ] ; } data ; apr_size_t i ; SVN_ERR_ASSERT ( size <= STREAM_THRESHOLD ) ; data . chunks [ ( size - 1 ) / sizeof ( apr_uint64_t ) ] = 0 ; SVN_ERR ( svn_io_file_read_full2 ( file , data . buffer , size , NULL , NULL , scratch_pool ) ) ; for ( i = 0 ; i < size / sizeof ( apr_uint64_t ) ; ++ i ) if ( data . chunks [ i ] != 0 ) break ; for ( i *= sizeof ( apr_uint64_t ) ; i < size ; ++ i ) if ( data . buffer [ i ] != 0 ) { const char * file_name ; apr_off_t offset ; SVN_ERR ( svn_io_file_name_get ( & file_name , file , scratch_pool ) ) ; SVN_ERR ( svn_fs_x__get_file_offset ( & offset , file , scratch_pool ) ) ; offset -= size - i ; return svn_error_createf ( SVN_ERR_FS_CORRUPT , NULL , _ ( " " " " ) , file_name , apr_off_t_toa ( scratch_pool , offset ) ) ; } return SVN_NO_ERROR ; }
Verify that the next SIZE bytes read from FILE are NUL.
Verify that the next SIZE bytes read from FILE are NUL .
/* read the whole data block; error out on failure */ /* chunky check */ /* byte-wise check upon mismatch or at the end of the block */