Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

问题反馈:hash_map_chaining.c中执行strcpy之前没有申请内存 #1576

Open
Aldebaran-ls opened this issue Nov 29, 2024 · 1 comment

Comments

@Aldebaran-ls
Copy link

第六章 哈希表->哈希冲突->链式地址
在hash_map_chaining.c添加操作'void put(HashMapChaining *hashMap, int key, const char *val)'函数中,
image
在执行strcpy(newPair->val, val)操作之前没有申请内存给newPair->val

image
在执行strcpy(cur->pair->val, val)之前如果新的val长度大于cur->pair->val也应该需要申请内存。

@Gonglja
Copy link
Contributor

Gonglja commented Dec 9, 2024

hash_map_chaining.c

newPair->val的类型是数组,在newPair时已经分配空间,不在需要对newPair->val使用 malloc 分配空间

可以使用 sizeof(struct Pair)验证一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants