-
Notifications
You must be signed in to change notification settings - Fork 254
Add and use memdup_T(), instead of its pattern #1296
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
base: master
Are you sure you want to change the base?
Conversation
f906dbd to
f09d8ec
Compare
f09d8ec to
d992542
Compare
d992542 to
5239d2b
Compare
|
I still recommend adding attribute |
|
See https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute
|
I think by having this function declared I don't like using attributes for telling the compiler that it can optimize. That's error-prone. I prefer allowing it to see more of the code, so it can reason by itself. |
Then you do not need current |
The |
e6e4c80 to
903035d
Compare
903035d to
ab7bb52
Compare
ab7bb52 to
06c665a
Compare
06c665a to
1b732db
Compare
d7eb6b8 to
a3f05ac
Compare
1360862 to
cfa78b2
Compare
cfa78b2 to
5899d2b
Compare
94b4a8d to
1cf10a6
Compare
|
Hard to review this PR as it has many not fully related changes. |
That's because this is queued after another PR. Here's how it looks in my computer: Once we merge the other branch, this will be small.
Thanks! |
ea60e66 to
4c5364d
Compare
172dcfb to
b4f9f0e
Compare
|
@Karlson2k , this is now ready. All dependencies have been merged. |
|
Looks good! |
741017f to
fbe2e3f
Compare
fbe2e3f to
98533af
Compare
98533af to
0e37949
Compare
This function already returned NULL on some errors. It didn't make any sense to exit(3) on allocation failure. Instead, just return NULL. Reviewed-by: "Evgeny Grin (Karlson2k)" <k2k@drgrin.dev> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…py(3) memcpy(3) is overkill, and much more dangerous than simple assignment. Simple assignment adds type safety, and removes any possibility of buffer overflow due to accidentally specifying a wrong size. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Cc: "Evgeny Grin (Karlson2k)" <k2k@drgrin.dev> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: "Evgeny Grin (Karlson2k)" <k2k@drgrin.dev> Signed-off-by: Alejandro Colomar <alx@kernel.org>
0e37949 to
4cd63b4
Compare
|
Cc: @kees |
See also: #1292 (comment)
Cc: @Karlson2k
Revisions:
v2
nparameter in MEMDUP(). I think we won't need it, as it will likely be1everywhere we might want to duplicate memory. The use of this API seems to be duplicating a pointer to structure that uses static storage in non-reentrant functions.?: 1trick. That's just for realloc(3).v2b
v3
v4
v4b
v4c
v4d
v5
s/MEMDUP/memdup_a/.v6
v6b
v6c
v6d
v7
v8
v9
v9b
v9c
v9d
v9e
v9f
v9g
v10
registerto disallow taking the address of compound literals.v10b
v11
v11b
v11c
v11d
v11e
v11f
v11g
v11h
v11i
v12
v13
(void)0within _Generic(3) to avoid -Wunused-value errors.v13b
v13c
v14
v14b
v14c
v14d