MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / lpValidateIntegrity

Function lpValidateIntegrity

src/listpack.c:933–965  ·  view source on GitHub ↗

Validate the integrity of the data structure. * when `deep` is 0, only the integrity of the header is validated. * when `deep` is 1, we scan all the entries one by one. */

Source from the content-addressed store, hash-verified

931 * when `deep` is 0, only the integrity of the header is validated.
932 * when `deep` is 1, we scan all the entries one by one. */
933int lpValidateIntegrity(unsigned char *lp, size_t size, int deep){
934 /* Check that we can actually read the header. (and EOF) */
935 if (size < LP_HDR_SIZE + 1)
936 return 0;
937
938 /* Check that the encoded size in the header must match the allocated size. */
939 size_t bytes = lpGetTotalBytes(lp);
940 if (bytes != size)
941 return 0;
942
943 /* The last byte must be the terminator. */
944 if (lp[size-1] != LP_EOF)
945 return 0;
946
947 if (!deep)
948 return 1;
949
950 /* Validate the invividual entries. */
951 uint32_t count = 0;
952 unsigned char *p = lp + LP_HDR_SIZE;
953 while(p && p[0] != LP_EOF) {
954 if (!lpValidateNext(lp, &p, bytes))
955 return 0;
956 count++;
957 }
958
959 /* Check that the count in the header is correct */
960 uint32_t numele = lpGetNumElements(lp);
961 if (numele != LP_HDR_NUMELE_UNKNOWN && numele != count)
962 return 0;
963
964 return 1;
965}

Callers 1

Calls 1

lpValidateNextFunction · 0.85

Tested by

no test coverage detected