Changeset 7dfe886 for util.c


Ignore:
Timestamp:
Jun 19, 2011, 2:44:13 AM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
b0e6560
Parents:
9d43dcc
git-author:
Jason Gross <jgross@mit.edu> (06/06/11 05:24:30)
git-committer:
Jason Gross <jgross@mit.edu> (06/19/11 02:44:13)
Message:
Use G_GNUC_WARN_UNUSED_RESULT

Have gcc warn us when we ignore the result of a function that requires
the caller to free the result, or an initilization function that can
fail.  This might help (slightly) with preventing leaks and segfaults.

Additionally changed some functions that should never fail to not
return values.  (The owl_list_* functions changed only fail if
list->size < 0, which we assume is not the case elsewhere.)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    r83a4af3 r7dfe886  
    3535 * duplicate slashes are removed.  Caller must free the return.
    3636 */
    37 char *owl_util_makepath(const char *in)
     37G_GNUC_WARN_UNUSED_RESULT char *owl_util_makepath(const char *in)
    3838{
    3939  int i, j, x;
     
    102102   to -1, argv will be NULL and the caller does not need to free anything. The
    103103   returned vector is NULL-terminated. */
    104 char **owl_parseline(const char *line, int *argc)
     104G_GNUC_WARN_UNUSED_RESULT char **owl_parseline(const char *line, int *argc)
    105105{
    106106  GPtrArray *argv;
     
    245245}
    246246
    247 char *owl_string_build_quoted(const char *tmpl, ...)
     247G_GNUC_WARN_UNUSED_RESULT char *owl_string_build_quoted(const char *tmpl, ...)
    248248{
    249249  GString *buf = g_string_new("");
     
    257257/* Returns a quoted version of arg suitable for placing in a
    258258 * command-line. Result should be freed with g_free. */
    259 char *owl_arg_quote(const char *arg)
     259G_GNUC_WARN_UNUSED_RESULT char *owl_arg_quote(const char *arg)
    260260{
    261261  GString *buf = g_string_new("");;
     
    265265
    266266/* caller must free the return */
    267 char *owl_util_minutes_to_timestr(int in)
     267G_GNUC_WARN_UNUSED_RESULT char *owl_util_minutes_to_timestr(int in)
    268268{
    269269  int days, hours;
     
    331331
    332332/* Get the default tty name.  Caller must free the return */
    333 char *owl_util_get_default_tty(void)
     333G_GNUC_WARN_UNUSED_RESULT char *owl_util_get_default_tty(void)
    334334{
    335335  const char *tmp;
     
    353353 * return.
    354354 */
    355 char *owl_util_stripnewlines(const char *in)
     355G_GNUC_WARN_UNUSED_RESULT char *owl_util_stripnewlines(const char *in)
    356356{
    357357 
     
    384384 * Error conditions are the same as g_file_read_link.
    385385 */
    386 gchar *owl_util_recursive_resolve_link(const char *filename)
     386G_GNUC_WARN_UNUSED_RESULT gchar *owl_util_recursive_resolve_link(const char *filename)
    387387{
    388388  gchar *last_path = g_strdup(filename);
     
    511511   The caller is responsible for freeing the allocated string.
    512512*/
    513 char * owl_util_baseclass(const char * class)
     513G_GNUC_WARN_UNUSED_RESULT char *owl_util_baseclass(const char *class)
    514514{
    515515  char *start, *end;
     
    546546
    547547/* Strips format characters from a valid utf-8 string. Returns the
    548    empty string if 'in' does not validate. */
    549 char * owl_strip_format_chars(const char *in)
     548   empty string if 'in' does not validate.  Caller must free the return. */
     549G_GNUC_WARN_UNUSED_RESULT char *owl_strip_format_chars(const char *in)
    550550{
    551551  char *r;
     
    584584 * out characters in Unicode Plane 16, as we use that plane internally
    585585 * for formatting.
    586  */
    587 char * owl_validate_or_convert(const char *in)
     586 * Caller must free the return.
     587 */
     588G_GNUC_WARN_UNUSED_RESULT char *owl_validate_or_convert(const char *in)
    588589{
    589590  if (g_utf8_validate(in, -1, NULL)) {
     
    599600 * Validate 'in' as UTF-8, and either return a copy of it, or an empty
    600601 * string if it is invalid utf-8.
    601  */
    602 char * owl_validate_utf8(const char *in)
     602 * Caller must free the return.
     603 */
     604G_GNUC_WARN_UNUSED_RESULT char *owl_validate_utf8(const char *in)
    603605{
    604606  char *out;
     
    632634}
    633635
    634 char *owl_escape_highbit(const char *str)
     636/* caller must free the return */
     637G_GNUC_WARN_UNUSED_RESULT char *owl_escape_highbit(const char *str)
    635638{
    636639  GString *out = g_string_new("");
     
    695698
    696699/* Read the rest of the input available in fp into a string. */
    697 char *owl_slurp(FILE *fp)
     700G_GNUC_WARN_UNUSED_RESULT char *owl_slurp(FILE *fp)
    698701{
    699702  char *buf = NULL;
Note: See TracChangeset for help on using the changeset viewer.