checkdata.h (3035B)
1 STATIC long long checkdata_coord_dispatch( 2 const char *, unsigned long long, const unsigned char *); 3 STATIC long long checkdata_coord( 4 const coord_t *, unsigned long long, const unsigned char *); 5 STATIC long long checkdata_multicoord( 6 const multicoord_t *, unsigned long long, const unsigned char *); 7 8 STATIC long long 9 checkdata_coord_dispatch( 10 const char *solver, 11 unsigned long long data_size, 12 const unsigned char *data 13 ) 14 { 15 coord_t *c; 16 multicoord_t *mc; 17 18 parse_coord_and_trans(solver, &c, &mc, NULL); 19 20 if (c != NULL) 21 return checkdata_coord(c, data_size, data); 22 23 if (mc != NULL) 24 return checkdata_multicoord(mc, data_size, data); 25 26 LOG("[cehckdata] Unknown coordinate solver '%s'\n", solver); 27 return NISSY_ERROR_DATA; 28 } 29 30 STATIC long long 31 checkdata_coord( 32 const coord_t *coord, 33 unsigned long long data_size, 34 const unsigned char *data 35 ) 36 { 37 const unsigned char *table; 38 tableinfo_t info; 39 int64_t err; 40 uint64_t actual_distribution[INFO_DISTRIBUTION_LEN]; 41 42 if ((size_t)data % 8 != 0) { 43 LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); 44 return NISSY_ERROR_DATA; 45 } 46 47 table = data + INFOSIZE; 48 err = readtableinfo(data_size, data, &info); 49 if (err != NISSY_OK) { 50 LOG("[checkdata] Data is corrupt\n"); 51 return err; 52 } 53 54 if (info.type != TABLETYPE_PRUNING) { 55 LOG("[checkdata] Skipping '%s'\n", info.solver); 56 table += info.next; 57 err = readtableinfo_n(data_size, data, 2, &info); 58 if (err != NISSY_OK) { 59 LOG("[checkdata] Data is corrupt\n"); 60 return err; 61 } 62 } 63 64 LOG("[checkdata] Checking distribution for '%s' from " 65 "table preamble\n", info.solver); 66 if (!distribution_equal(coord->pruning_distribution, 67 info.distribution, coord->pruning_max)) { 68 LOG("[checkdata] Distribution from the table preamble does " 69 "not match the expected one\n"); 70 return NISSY_ERROR_DATA; 71 } 72 73 LOG("\n[checkdata] Checking distribution for '%s' from " 74 "actual table\n", info.solver); 75 getdistribution(table, actual_distribution, &info); 76 if (!distribution_equal(coord->pruning_distribution, 77 actual_distribution, coord->pruning_max)) { 78 LOG("[checkdata] Distribution from the actual table does " 79 "not match the expected one\n"); 80 return NISSY_ERROR_DATA; 81 } 82 83 return NISSY_OK; 84 } 85 86 STATIC long long 87 checkdata_multicoord( 88 const multicoord_t *mcoord, 89 unsigned long long data_size, 90 const unsigned char *data 91 ) 92 { 93 long long r; 94 size_t i, of, s; 95 96 for (of = INFOSIZE, i = 0; mcoord->coordinates[i] != NULL; i++) { 97 LOG("[checkdata] %s: checking data for %s\n", mcoord->name, 98 mcoord->coordinates[i]->name); 99 s = gendata_coord(mcoord->coordinates[i], NULL); 100 if (s > data_size-of) 101 return NISSY_ERROR_DATA; 102 103 r = checkdata_coord(mcoord->coordinates[i], s, data + of); 104 if (r != NISSY_OK) 105 return r; 106 107 LOG("[checkdata] Ok\n"); 108 109 of += s; 110 111 /* Skip padding */ 112 while (of % 8 != 0) { 113 if (data[of] != 0) 114 LOG("[checkdata] Warning: some unused bytes " 115 "are not set to zero. Please report this " 116 "bug.\n"); 117 of++; 118 } 119 } 120 121 return NISSY_OK; 122 }