diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2015-08-13 20:51:51 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2015-08-13 20:51:51 +0200 |
commit | a56fec820b9a7ac772ff233a9510180ad782afd0 (patch) | |
tree | cda5095829be6a7c3370897a24a378e004b3710a /src | |
parent | 4716e81d4e0f94cfed9a3e2b4dc103bf4bf83459 (diff) | |
download | weechat-a56fec820b9a7ac772ff233a9510180ad782afd0.zip |
python: fix cppcheck error on variable "python2_bin" (closes #486)
This fixes only a wrong error report from cppcheck, there was no problem
in code with the variable "python2_bin".
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/python/weechat-python.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index 2eccf3720..eb382d0d2 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -114,19 +114,21 @@ char python_buffer_output[128]; /* - * Sets path to python 2.x interpreter. + * Gets path to python 2.x interpreter. + * + * Note: result must be freed after use. */ -void -weechat_python_set_python2_bin () +char * +weechat_python_get_python2_bin () { const char *dir_separator; - char *path, **paths, bin[4096]; + char *py2_bin, *path, **paths, bin[4096]; char *versions[] = { "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2", NULL }; int num_paths, i, j, rc; struct stat stat_buf; - python2_bin = NULL; + py2_bin = NULL; dir_separator = weechat_info_get ("dir_separator", ""); path = getenv ("PATH"); @@ -146,19 +148,21 @@ weechat_python_set_python2_bin () rc = stat (bin, &stat_buf); if ((rc == 0) && (S_ISREG(stat_buf.st_mode))) { - python2_bin = strdup (bin); + py2_bin = strdup (bin); break; } } - if (python2_bin) + if (py2_bin) break; } weechat_string_free_split (paths); } } - if (!python2_bin) - python2_bin = strdup ("python"); + if (!py2_bin) + py2_bin = strdup ("python"); + + return py2_bin; } /* @@ -1061,7 +1065,7 @@ weechat_python_info_cb (void *data, const char *info_name, if ((rc != 0) || (!S_ISREG(stat_buf.st_mode))) { free (python2_bin); - weechat_python_set_python2_bin (); + python2_bin = weechat_python_get_python2_bin (); } } return python2_bin; @@ -1273,7 +1277,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) * hook info to get path to python 2.x interpreter * (some scripts using hook_process need that) */ - weechat_python_set_python2_bin (); + python2_bin = weechat_python_get_python2_bin (); weechat_hook_info ("python2_bin", N_("path to python 2.x interpreter"), NULL, |