geanypg: Simplify string building a lot

Use `g_strdup_printf()` instead of manually computing the string size
and then `sprintf()` in it.  This makes the code a lot simpler and less
likely to break when changed as there is no more error-prone code
duplication.

Also, fix the size passed to `strncpy()` to make sure the strings are
always properly nul-terminated.