你永远不用于分配空间comp->highest_committed_vs
,你检查comp
的NULL
非关联化之后.试试这样吧
int main() { consensus_component *comp = malloc(sizeof(consensus_component)); if (comp == NULL) return -1; memset(comp, 0, sizeof(consensus_component)); comp->highest_committed_vs = malloc(sizeof(*comp->highest_committed_vs)); if (comp->highest_committed_vs == NULL) { free(comp); return -1; } comp->highest_committed_vs->view_id = 1; comp->highest_committed_vs->req_id = 0; db_key_type start = vstol(comp->highest_committed_vs)+1; printf("%" PRIu64 "\n", start); return 0; }