| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | Feilong Meng <feelingmeng(at)foxmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: [PATCH]Remove the redundant assignment |
| Date: | 2025-12-16 07:08:25 |
| Message-ID: | BEA88676-EAFB-4E2E-9380-3B0029FE19E3@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Dec 16, 2025, at 14:18, Feilong Meng <feelingmeng(at)foxmail(dot)com> wrote:
>
> Hi,Hackers,
>
> I found that in the InjectionPointAttach function within the src/backend/utils/misc/injection_point.c file, the variable is manually assigned a '\0' at the end, even though strlcpy already guarantees that the destination buffer will be null-terminated and will not overflow.
>
> The code modification is as follows:
>
> ```
> /* Save the entry */
> strlcpy(entry->name, name, sizeof(entry->name));
> entry->name[INJ_NAME_MAXLEN - 1] = '\0'; <== Delete this line
> strlcpy(entry->library, library, sizeof(entry->library));
> entry->library[INJ_LIB_MAXLEN - 1] = '\0'; <== Delete this line
> strlcpy(entry->function, function, sizeof(entry->function));
> entry->function[INJ_FUNC_MAXLEN - 1] = '\0'; <== Delete this line
> ```
>
> And in the injection_point_cache_add function within the same file, strlcpy(entry->name, name, sizeof(entry->name)); does not perform redundant assignment.
>
> I have tested the change, and "make check" passed.
>
Indeed, explicitly adding a trailing '\0' is redundant here, since strlcpy() already guarantees NULL termination.
I also noticed that in the same file, another code path does not perform this extra assignment:
```
Assert(!found);
strlcpy(entry->name, name, sizeof(entry->name));
entry->slot_idx = slot_idx;
entry->generation = generation;
entry->callback = callback;
memcpy(entry->private_data, private_data, INJ_PRIVATE_MAXLEN);
```
Given that, I agree we should remove the redundant assignments to keep the code clearer and consistent.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nitin Jadhav | 2025-12-16 07:10:25 | Re: Fix crash during recovery when redo segment is missing |
| Previous Message | Arunprasad Rajkumar | 2025-12-16 07:07:55 | Re: [PATCH] Skip unpublishable child tables when adding parent to publication |