From b5ef1bd79a8aec50a7b4b921721a036d65134e18 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Thu, 2 Sep 2004 14:48:21 +0000 Subject: [PATCH] * HACKING: Added a section "Programming Tips" which lists mistakes that have been done once and should never be repeated. --- ChangeLog | 5 +++++ HACKING | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index 62eed9e95..26a8fad97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-09-02 Roland Illig + + * HACKING: Added a section "Programming Tips" which lists mistakes + that have been done once and should never be repeated. + 2004-08-29 Roland Illig * m4/ri-gcc-warnings.m4: Now handles only the last --enable or diff --git a/HACKING b/HACKING index 7dcfe407f..d29565d33 100644 --- a/HACKING +++ b/HACKING @@ -275,3 +275,24 @@ widgets. Some widgets also have user callbacks. To create your own widget, use init_widget(). In this case, you must provide a callback function. Please note that it's not the same as the user callback in some widgets. + + +PROGRAMMING TIPS +================ + +const: For every function taking a string argument, decide whether you + (as a user of the function) would expect that the string is modi- + fied by the function. If not, declare the string argument as + "const char *". If your implementation needs to modify the string, + use g_strdup to create a local copy. + +g_strlcpy: Whenever you use this function, be sure to add "glib-compat.h" + to the included headers. This is because in glib-1.2 there is + no such function. + +size_t: This data type is suitable for expressing sizes of memory or the + length of strings. This type is unsigned, so you need not check + if the value is >= 0. + +strncpy: Don't use this function in newly created code. It is slow, insecure + and hard to use. A much better alternative is g_strlcpy (see there).