diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-12 11:11:28 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-12 11:11:28 +0200 |
| commit | da8fdd4955fd24666643915a6728678e9965a0d3 (patch) | |
| tree | 878d7baf68f90e80949bc79a039bda159865821f /src/nissy.h | |
| parent | 14689e29252e608d51c5b52e61e43471d2aa021e (diff) | |
| download | nissy-core-da8fdd4955fd24666643915a6728678e9965a0d3.tar.gz nissy-core-da8fdd4955fd24666643915a6728678e9965a0d3.zip | |
Make writecube safer
Diffstat (limited to '')
| -rw-r--r-- | src/nissy.h | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/nissy.h b/src/nissy.h index d4c2760..f91ee63 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -35,11 +35,17 @@ for example 'rotation UF' or 'mirrored BL'. | |||
| 35 | #define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) | 35 | #define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) |
| 36 | #define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) | 36 | #define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) |
| 37 | #define NISSY_ERROR_NULL_POINTER INT64_C(-60) | 37 | #define NISSY_ERROR_NULL_POINTER INT64_C(-60) |
| 38 | #define NISSY_ERROR_BUFFER_SIZE INT64_C(-61) | ||
| 38 | #define NISSY_ERROR_DATA INT64_C(-70) | 39 | #define NISSY_ERROR_DATA INT64_C(-70) |
| 39 | #define NISSY_ERROR_OPTIONS INT64_C(-80) | 40 | #define NISSY_ERROR_OPTIONS INT64_C(-80) |
| 40 | #define NISSY_ERROR_INVALID_CODE INT64_C(-90) | 41 | #define NISSY_ERROR_INVALID_CODE INT64_C(-90) |
| 41 | #define NISSY_ERROR_UNKNOWN INT64_C(-999) | 42 | #define NISSY_ERROR_UNKNOWN INT64_C(-999) |
| 42 | 43 | ||
| 44 | /* Some constants for size for I/O buffers */ | ||
| 45 | #define NISSY_SIZE_B32 UINT64_C(22) | ||
| 46 | #define NISSY_SIZE_H48 UINT64_C(88) | ||
| 47 | #define NISSY_SIZE_TRANSFORMATION UINT64_C(12) | ||
| 48 | |||
| 43 | /* Flags for NISS options */ | 49 | /* Flags for NISS options */ |
| 44 | #define NISSY_NISSFLAG_NORMAL UINT8_C(1) | 50 | #define NISSY_NISSFLAG_NORMAL UINT8_C(1) |
| 45 | #define NISSY_NISSFLAG_INVERSE UINT8_C(2) | 51 | #define NISSY_NISSFLAG_INVERSE UINT8_C(2) |
| @@ -68,9 +74,9 @@ Return values: | |||
| 68 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 74 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| 69 | */ | 75 | */ |
| 70 | int64_t nissy_compose( | 76 | int64_t nissy_compose( |
| 71 | const char cube[static 22], | 77 | const char cube[static NISSY_SIZE_B32], |
| 72 | const char permutation[static 22], | 78 | const char permutation[static NISSY_SIZE_B32], |
| 73 | char result[static 22] | 79 | char result[static NISSY_SIZE_B32] |
| 74 | ); | 80 | ); |
| 75 | 81 | ||
| 76 | /* | 82 | /* |
| @@ -89,8 +95,8 @@ Return values: | |||
| 89 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 95 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| 90 | */ | 96 | */ |
| 91 | int64_t nissy_inverse( | 97 | int64_t nissy_inverse( |
| 92 | const char cube[static 22], | 98 | const char cube[static NISSY_SIZE_B32], |
| 93 | char result[static 22] | 99 | char result[static NISSY_SIZE_B32] |
| 94 | ); | 100 | ); |
| 95 | 101 | ||
| 96 | /* | 102 | /* |
| @@ -111,9 +117,9 @@ Return values: | |||
| 111 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. | 117 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. |
| 112 | */ | 118 | */ |
| 113 | int64_t nissy_applymoves( | 119 | int64_t nissy_applymoves( |
| 114 | const char cube[static 22], | 120 | const char cube[static NISSY_SIZE_B32], |
| 115 | const char *moves, | 121 | const char *moves, |
| 116 | char result[static 22] | 122 | char result[static NISSY_SIZE_B32] |
| 117 | ); | 123 | ); |
| 118 | 124 | ||
| 119 | /* | 125 | /* |
| @@ -132,9 +138,9 @@ Return values: | |||
| 132 | NISSY_ERROR_INVALID_TRANS - The given transformation is invalid. | 138 | NISSY_ERROR_INVALID_TRANS - The given transformation is invalid. |
| 133 | */ | 139 | */ |
| 134 | int64_t nissy_applytrans( | 140 | int64_t nissy_applytrans( |
| 135 | const char cube[static 22], | 141 | const char cube[static NISSY_SIZE_B32], |
| 136 | const char transformation[static 12], | 142 | const char transformation[static NISSY_SIZE_TRANSFORMATION], |
| 137 | char result[static 22] | 143 | char result[static NISSY_SIZE_B32] |
| 138 | ); | 144 | ); |
| 139 | 145 | ||
| 140 | /* | 146 | /* |
| @@ -154,7 +160,7 @@ Return values: | |||
| 154 | */ | 160 | */ |
| 155 | int64_t nissy_frommoves( | 161 | int64_t nissy_frommoves( |
| 156 | const char *moves, | 162 | const char *moves, |
| 157 | char result[static 22] | 163 | char result[static NISSY_SIZE_B32] |
| 158 | ); | 164 | ); |
| 159 | 165 | ||
| 160 | /* | 166 | /* |
| @@ -169,6 +175,7 @@ Parameters: | |||
| 169 | 175 | ||
| 170 | Return values: | 176 | Return values: |
| 171 | NISSY_OK - The conversion was performed succesfully. | 177 | NISSY_OK - The conversion was performed succesfully. |
| 178 | NISSY_ERROR_BUFFER_SIZE - The given buffer is too small for the result. | ||
| 172 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. | 179 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. |
| 173 | NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid. | 180 | NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid. |
| 174 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 181 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| @@ -208,7 +215,7 @@ int64_t nissy_getcube( | |||
| 208 | int64_t cp, | 215 | int64_t cp, |
| 209 | int64_t co, | 216 | int64_t co, |
| 210 | const char *options, | 217 | const char *options, |
| 211 | char result[static 22] | 218 | char result[static NISSY_SIZE_B32] |
| 212 | ); | 219 | ); |
| 213 | 220 | ||
| 214 | /* | 221 | /* |
| @@ -313,7 +320,7 @@ Return values: | |||
| 313 | Any value >= 0 - The number of solutions found. | 320 | Any value >= 0 - The number of solutions found. |
| 314 | */ | 321 | */ |
| 315 | int64_t nissy_solve( | 322 | int64_t nissy_solve( |
| 316 | const char cube[static 22], | 323 | const char cube[static NISSY_SIZE_B32], |
| 317 | const char *solver, | 324 | const char *solver, |
| 318 | uint8_t nissflag, | 325 | uint8_t nissflag, |
| 319 | int8_t minmoves, | 326 | int8_t minmoves, |
