db_tutorial
db_tutorial copied to clipboard
deserialize_row the '\0' problem
void deserialize_row(void* source, Row* destination) {
memcpy(&(destination->id), source + ID_OFFSET, ID_SIZE);
memcpy(&(destination->username), source + USERNAME_OFFSET, USERNAME_SIZE);
memcpy(&(destination->email), source + EMAIL_OFFSET, EMAIL_SIZE);
}
We know that the clang stirng was terminated by '\0'. Copy the entire buffer in the deserialize_row method. char username[USERNAME_SIZE] in Row is csstack, username[7] was not set '\0' explicitly. If the value of username[7] is not '\0', when execute 'select', this may be wrong. I can't write proper code, my platform is ubuntu18.04. Is there someone can provide the code running properly on Ubuntu? Thanks a lot.
I ran on Ubuntu 20.04. It worked.
But I do not understand why need to compute the size of every field and the ROW_SIZE.
I tried that count uint32_t ROW_SIZE = sizeof(ROW); and the result was the same.