RE: https://mastodon.social/@bagder/115805010608994033

Qué interesante este post de @bagder sobre el uso de #strcpy vs #strncpy en C.

Siempre vi que la recomendación era usar strncpy en vez de strcpy.

El problema de strcpy es que no controla los límites de buffers, mientras que strncpy sí, pero a la vez, tiene sus propios problemas.

El uso de #snprintf me parece interesante como reemplazo, o directamente una implementación manual como la que se plantea con curlx_strcopy.

BTW, qué ganas tengo de programar en #C ahora xD

#linux #curl #dev

🚨 Breaking News: "Programmer discovers #strncpy is bad! 🎉" In a shocking revelation, it turns out using a function that doesn't null-terminate strings can lead to problems. Who would have thought? Next, Daniel plans to tackle the #mysteries of 'printf' – stay tuned! 🤔
https://daniel.haxx.se/blog/2025/12/29/no-strcpy-either/ #BreakingNews #ProgrammerProblems #Issues #printf #HackerNews #ngated
no strcpy either

Some time ago I mentioned that we went through the curl source code and eventually got rid of all strncpy() calls. strncpy() is a weird function with a crappy API. It might not null terminate the destination and it pads the target buffer with zeroes. Quite frankly, most code bases are probably better off completely … Continue reading no strcpy either →

daniel.haxx.se