gentoobro on Nostr: Yes. There's basically no reason to use strtok ever. You can't (shouldn't) modify ...
Yes. There's basically no reason to use strtok ever. You can't (shouldn't) modify string literals, so it's possible that you could segfault if a pointer to a string literal got passed to strtok, depending on your system and if it locks the section containing the memory for string literals. Also, if I recall, it's not reentrant.
A basic loop with strchr can replace it, though in modern not-super-performance-sensitive code you really should just write a function like char\*\* strsplit(char\* in, char\* sep) that returns a malloc'd, null-terminated list of pointers to malloc'd null-terminated strings. Memory allocation is not the super slow bugbear it used to be.
Published at
2024-09-03 04:39:09Event JSON
{
"id": "975a732d52757bb414ec00ae7cae20764a41a4cc8290ef565de96ed74c27a7c0",
"pubkey": "bf4354c655785fa9364dc9499bd2c7a41acbbaa17bf778d977983d5ac8a438b1",
"created_at": 1725338349,
"kind": 1,
"tags": [
[
"p",
"69ab6e8a85d5c9d3a63375bfe3e9bb8aecfb13417131613e215caff4a8b62cac"
],
[
"e",
"ad87e0ba60216d2c8d344c97ed91faf10614da3e5f18a25257fe1aa3cf090d8b",
"",
"root",
"69ab6e8a85d5c9d3a63375bfe3e9bb8aecfb13417131613e215caff4a8b62cac"
],
[
"proxy",
"https://shitpost.cloud/objects/e848ee5f-b245-4f18-bbb6-72e540fb0eb6",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://shitpost.cloud/objects/e848ee5f-b245-4f18-bbb6-72e540fb0eb6",
"pink.momostr"
],
[
"-"
]
],
"content": "Yes. There's basically no reason to use strtok ever. You can't (shouldn't) modify string literals, so it's possible that you could segfault if a pointer to a string literal got passed to strtok, depending on your system and if it locks the section containing the memory for string literals. Also, if I recall, it's not reentrant. \n\nA basic loop with strchr can replace it, though in modern not-super-performance-sensitive code you really should just write a function like char\\*\\* strsplit(char\\* in, char\\* sep) that returns a malloc'd, null-terminated list of pointers to malloc'd null-terminated strings. Memory allocation is not the super slow bugbear it used to be.",
"sig": "b0783f6c4fe38afedd45c249d2a43d9a14bd0a25063cbe39fe1641646dffe3aee4f8bc4b29d5ead73b6cd0b269278a297d5bd77022f9f378d2debc0bdb6c1213"
}