matrix:
include:
- os: osx
- osx_image: xcode10.1
+ osx_image: xcode11.2
compiler: clang
+ jdk: openjdk10
env:
- CXX=clang++
- PATH="/usr/local/opt/mysql-client/bin:$PATH"
+ - JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk-13.jdk/Contents/Home"
- os: linux
dist: xenial
compiler: clang
+ jdk: openjdk10
- os: linux
dist: xenial
compiler: gcc
+ jdk: openjdk10
before_install:
# When building the coverity_scan branch, allow only the first job to continue to avoid travis-ci/travis-ci#1975.
script:
- if [[ "${TRAVIS_BRANCH}" == "coverity_scan" ]]; then exit 0; fi
+ - type pkg-config
+ - pkg-config --list-all | sort -u
- ./configure
+ - cat config.log
- make distcheck DISTCHECK_CONFIGURE_FLAGS="--disable-dependency-tracking --enable-debug"
addons:
- liblua50-dev
- liblua5.1-0-dev
- liblua5.2-dev
- - liblvm2-dev
- libmemcached-dev
- libmicrohttpd-dev
- libmnl-dev
- libsensors4-dev
- libsigrok-dev
- libsnmp-dev
- - libstatgrab-dev
- libtokyocabinet-dev
- libtokyotyrant-dev
- libudev-dev
packages:
- curl
- glib
+ - grpc
- hiredis
- libdbi
- libmemcached
- liboping
- libpcap
- librdkafka
- - libstatgrab
- libvirt
+ - libxml2
- lua
+ - mongo-c-driver
- mosquitto
- mysql-client
- net-snmp
lua_la_LIBADD = $(BUILD_WITH_LIBLUA_LIBS)
endif
-if BUILD_PLUGIN_LVM
-pkglib_LTLIBRARIES += lvm.la
-lvm_la_SOURCES = src/lvm.c
-lvm_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBLVM2APP_CPPFLAGS)
-lvm_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBLVM2APP_LDFLAGS)
-lvm_la_LIBADD = $(BUILD_WITH_LIBLVM2APP_LIBS)
-endif
-
if BUILD_PLUGIN_MADWIFI
pkglib_LTLIBRARIES += madwifi.la
madwifi_la_SOURCES = \
collectd without the need to start a heavy interpreter every interval.
See collectd-lua(5) for details.
- - lvm
- Size of “Logical Volumes” (LV) and “Volume Groups” (VG) of Linux'
- “Logical Volume Manager” (LVM).
-
- madwifi
Queries very detailed usage statistics from wireless LAN adapters and
interfaces that use the Atheros chipset and the MadWifi driver.
Used by the `lua' plugin. Currently, Lua 5.1 and later are supported.
<https://www.lua.org/>
- * liblvm2 (optional)
- Used by the `lvm' plugin.
- <ftp://sources.redhat.com/pub/lvm2/>
-
* libmemcached (optional)
Used by the `memcachec' plugin to connect to a memcache daemon.
<http://tangent.org/552/libmemcached.html>
#
AC_CHECK_FUNCS_ONCE([ \
asprintf \
+ execvpe \
getpwnam \
getpwnam_r \
if_indextoname \
- setenv \
setgroups \
setlocale
]
else
AC_MSG_RESULT([no])
with_libgrpcpp="no (requires C++11 support)"
+ with_libprotobuf="no (<google/protobuf/util/time_util.h> requires C++11 support)"
fi
fi
AC_SUBST(BUILD_WITH_LIBLUA_LIBS)
# }}}
-# --with-liblvm2app {{{
-AC_ARG_WITH([liblvm2app],
- [AS_HELP_STRING([--with-liblvm2app@<:@=PREFIX@:>@], [Path to liblvm2app.])],
- [
- if test "x$withval" = "xno"; then
- with_liblvm2app="no"
- else
- with_liblvm2app="yes"
- if test "x$withval" != "xyes"; then
- with_liblvm2app_cppflags="-I$withval/include"
- with_liblvm2app_ldflags="-L$withval/lib"
- fi
- fi
- ],
- [
- if test "x$ac_system" = "xLinux"; then
- with_liblvm2app="yes"
- else
- with_liblvm2app="no (Linux only library)"
- fi
- ]
-)
-
-if test "x$with_liblvm2app" = "xyes"; then
- SAVE_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
-
- AC_CHECK_HEADERS([lvm2app.h],
- [with_liblvm2app="yes"],
- [with_liblvm2app="no (lvm2app.h not found)"]
- )
-
- CPPFLAGS="$SAVE_CPPFLAGS"
-fi
-
-if test "x$with_liblvm2app" = "xyes"; then
- SAVE_CPPFLAGS="$CPPFLAGS"
- SAVE_LDFLAGS="$LDFLAGS"
- CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
- LDFLAGS="$LDFLAGS $with_liblvm2app_ldflags"
-
- AC_CHECK_LIB([lvm2app], [lvm_lv_get_property],
- [with_liblvm2app="yes"],
- [with_liblvm2app="no (Symbol 'lvm_lv_get_property' not found)"]
- )
-
- CPPFLAGS="$SAVE_CPPFLAGS"
- LDFLAGS="$SAVE_LDFLAGS"
-fi
-
-if test "x$with_liblvm2app" = "xyes"; then
- BUILD_WITH_LIBLVM2APP_CPPFLAGS="$with_liblvm2app_cppflags"
- BUILD_WITH_LIBLVM2APP_LDFLAGS="$with_liblvm2app_ldflags"
- BUILD_WITH_LIBLVM2APP_LIBS="-llvm2app"
-fi
-
-AC_SUBST([BUILD_WITH_LIBLVM2APP_CPPFLAGS])
-AC_SUBST([BUILD_WITH_LIBLVM2APP_LDFLAGS])
-AC_SUBST([BUILD_WITH_LIBLVM2APP_LIBS])
-# }}}
-
# --with-libmemcached {{{
AC_ARG_WITH([libmemcached],
[AS_HELP_STRING([--with-libmemcached@<:@=PREFIX@:>@], [Path to libmemcached.])],
AC_CHECK_LIB([protobuf], [main],
[
SAVE_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$with_libprotobuf_cppflags $PROTOBUF_CFLAGS"
+ CPPFLAGS="-std=c++11 $with_libprotobuf_cppflags $PROTOBUF_CFLAGS"
if test "x$PROTOBUF_LIBS" = "x"
then
PROTOBUF_LIBS="-lprotobuf"
plugin_ipc="yes"
plugin_irq="yes"
plugin_load="yes"
- plugin_lvm="yes"
plugin_mcelog="yes"
plugin_memory="yes"
plugin_nfs="yes"
AC_PLUGIN([logfile], [yes], [File logging plugin])
AC_PLUGIN([lpar], [$with_perfstat], [AIX logical partitions statistics])
AC_PLUGIN([lua], [$with_liblua], [Lua plugin])
-AC_PLUGIN([lvm], [$with_liblvm2app], [LVM statistics])
AC_PLUGIN([madwifi], [$have_linux_wireless_h], [Madwifi wireless statistics])
AC_PLUGIN([match_empty_counter], [yes], [The empty counter match])
AC_PLUGIN([match_hashed], [yes], [The hashed match])
AC_MSG_RESULT([ libkvm . . . . . . . $with_libkvm])
AC_MSG_RESULT([ libldap . . . . . . . $with_libldap])
AC_MSG_RESULT([ liblua . . . . . . . $with_liblua])
-AC_MSG_RESULT([ liblvm2app . . . . . $with_liblvm2app])
AC_MSG_RESULT([ libmemcached . . . . $with_libmemcached])
AC_MSG_RESULT([ libmicrohttpd . . . . $with_libmicrohttpd])
AC_MSG_RESULT([ libmnl . . . . . . . $with_libmnl])
AC_MSG_RESULT([ log_logstash . . . . $enable_log_logstash])
AC_MSG_RESULT([ lpar . . . . . . . . $enable_lpar])
AC_MSG_RESULT([ lua . . . . . . . . . $enable_lua])
-AC_MSG_RESULT([ lvm . . . . . . . . . $enable_lvm])
AC_MSG_RESULT([ madwifi . . . . . . . $enable_madwifi])
AC_MSG_RESULT([ match_empty_counter . $enable_match_empty_counter])
AC_MSG_RESULT([ match_hashed . . . . $enable_match_hashed])
%define with_log_logstash 0%{!?_without_log_logstash:1}
%define with_logfile 0%{!?_without_logfile:1}
%define with_lua 0%{!?_without_lua:1}
-%define with_lvm 0%{!?_without_lvm:1}
%define with_madwifi 0%{!?_without_madwifi:1}
%define with_mbmon 0%{!?_without_mbmon:1}
%define with_mcelog 0%{!?_without_mcelog:1}
%define with_gmond 0
%define with_iptables 0
%define with_ipvs 0
-%define with_lvm 0
%define with_modbus 0
%define with_netlink 0
%define with_redis 0
Summary: Statistics collection and monitoring daemon
Name: collectd
-Version: 5.9.0
-Release: 1%{?dist}
+Version: 5.9.2
+Release: 2%{?dist}
URL: https://collectd.org
Source: https://collectd.org/files/%{name}-%{version}.tar.bz2
License: GPLv2
application programming interface (API) to Lua scripts.
%endif
-%if %{with_lvm}
-%package lvm
-Summary: LVM plugin for collectd
-Group: System Environment/Daemons
-Requires: %{name}%{?_isa} = %{version}-%{release}
-BuildRequires: lvm2-devel
-%description lvm
-This plugin collects size of “Logical Volumes” (LV) and “Volume Groups” (VG)
-of Linux' “Logical Volume Manager” (LVM).
-%endif
-
%if %{with_mcelog}
%package mcelog
Summary: Mcelog plugin for collectd
%define _with_lua --disable-lua
%endif
-%if %{with_lvm}
-%define _with_lvm --enable-lvm
-%else
-%define _with_lvm --disable-lvm
-%endif
-
%if %{with_madwifi}
%define _with_madwifi --enable-madwifi
%else
%{?_with_logfile} \
%{?_with_lpar} \
%{?_with_lua} \
- %{?_with_lvm} \
%{?_with_madwifi} \
%{?_with_mbmon} \
%{?_with_mcelog} \
%{_libdir}/%{name}/lua.so
%endif
-%if %{with_lvm}
-%files lvm
-%{_libdir}/%{name}/lvm.so
-%endif
-
%if %{with_memcachec}
%files memcachec
%{_libdir}/%{name}/memcachec.so
%doc contrib/
%changelog
+* Mon Oct 14 2019 Ruben Kerkhof <ruben@rubenkerkhof.com> - 5.9.2-2
+- Remove lvm plugin, liblvmapp has been deprecated upstream
+
* Fri Jun 14 2019 Fabien Wernli <rpmbuild@faxmodem.org> - 5.9.0-1
- add code for write_stackdriver (disabled for now)
- add code for gpu_nvidia (disabled for now)
@BUILD_PLUGIN_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
#@BUILD_PLUGIN_LPAR_TRUE@LoadPlugin lpar
#@BUILD_PLUGIN_LUA_TRUE@LoadPlugin lua
-#@BUILD_PLUGIN_LVM_TRUE@LoadPlugin lvm
#@BUILD_PLUGIN_MADWIFI_TRUE@LoadPlugin madwifi
#@BUILD_PLUGIN_MBMON_TRUE@LoadPlugin mbmon
#@BUILD_PLUGIN_MCELOG_TRUE@LoadPlugin mcelog
#define _DEFAULT_SOURCE
#define _BSD_SOURCE /* For setgroups */
+/* _GNU_SOURCE is needed in Linux to use execvpe */
+#define _GNU_SOURCE
+
#include "collectd.h"
#include "plugin.h"
#include <sys/capability.h>
#endif
+extern char **environ;
+
#define PL_NORMAL 0x01
#define PL_NOTIF_ACTION 0x02
return 0;
} /* int exec_config }}} */
-#if !defined(HAVE_SETENV)
-static char env_interval[64];
-// max hostname len is 255, so this should be enough
-static char env_hostname[300];
-#endif
-
-static void set_environment(void) /* {{{ */
-{
-#ifdef HAVE_SETENV
- char buffer[1024];
-
- snprintf(buffer, sizeof(buffer), "%.3f",
- CDTIME_T_TO_DOUBLE(plugin_get_interval()));
- setenv("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1);
-
- sstrncpy(buffer, hostname_g, sizeof(buffer));
- setenv("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1);
-#else
- snprintf(env_interval, sizeof(env_interval), "COLLECTD_INTERVAL=%.3f",
- CDTIME_T_TO_DOUBLE(plugin_get_interval()));
- putenv(env_interval);
-
- snprintf(env_hostname, sizeof(env_hostname), "COLLECTD_HOSTNAME=%s",
- hostname_g);
- putenv(env_hostname);
-#endif
-} /* }}} void set_environment */
-
-static void unset_environment(void) /* {{{ */
-{
-#ifdef HAVE_SETENV
- unsetenv("COLLECTD_INTERVAL");
- unsetenv("COLLECTD_HOSTNAME");
-#else
- snprintf(env_interval, sizeof(env_interval), "COLLECTD_INTERVAL");
- putenv(env_interval);
- snprintf(env_hostname, sizeof(env_hostname), "COLLECTD_HOSTNAME");
- putenv(env_hostname);
-#endif
-} /* }}} void unset_environment */
-
-__attribute__((noreturn)) static void exec_child(program_list_t *pl, int uid,
- int gid, int egid) /* {{{ */
+__attribute__((noreturn)) static void exec_child(program_list_t *pl,
+ char **envp, int uid, int gid,
+ int egid) /* {{{ */
{
int status;
exit(-1);
}
+#ifdef HAVE_EXECVPE
+ execvpe(pl->exec, pl->argv, envp);
+#else
+ environ = envp;
execvp(pl->exec, pl->argv);
+#endif
ERROR("exec plugin: Failed to execute ``%s'': %s", pl->exec, STRERRNO);
exit(-1);
goto failed;
}
- set_environment();
+ double interval = CDTIME_T_TO_DOUBLE(plugin_get_interval());
pid = fork();
if (pid < 0) {
ERROR("exec plugin: fork failed: %s", STRERRNO);
goto failed;
} else if (pid == 0) {
- int fd_num;
+ char interval_buf[128];
+ snprintf(interval_buf, sizeof(interval_buf), "COLLECTD_INTERVAL=%.3f",
+ interval);
+
+ /* max hostname len is 255, so this should be enough */
+ char hostname_buf[300];
+ snprintf(hostname_buf, sizeof(hostname_buf), "COLLECTD_HOSTNAME=%s",
+ hostname_g);
+
+ size_t env_size = 0;
+ while (environ[env_size] != NULL) {
+ ++env_size;
+ }
+
+ /* Copy the environment variables */
+ char *envp[env_size + 3];
+ size_t envp_idx;
+ for (envp_idx = 0; environ[envp_idx] != NULL && envp_idx < env_size;
+ ++envp_idx) {
+ envp[envp_idx] = environ[envp_idx];
+ }
+
+ /* Add the collectd environment variables */
+ envp[envp_idx++] = interval_buf;
+ envp[envp_idx++] = hostname_buf;
+ envp[envp_idx++] = NULL;
/* Close all file descriptors but the pipe end we need. */
- fd_num = getdtablesize();
+ int fd_num = getdtablesize();
for (int fd = 0; fd < fd_num; fd++) {
if ((fd == fd_pipe_in[0]) || (fd == fd_pipe_out[1]) ||
(fd == fd_pipe_err[1]))
/* Unblock all signals */
reset_signal_mask();
- exec_child(pl, uid, gid, egid);
+ exec_child(pl, envp, uid, gid, egid);
/* does not return */
}
- unset_environment();
-
close(fd_pipe_in[0]);
close(fd_pipe_out[1]);
close(fd_pipe_err[1]);
return pid;
failed:
- unset_environment();
-
close_pipe(fd_pipe_in);
close_pipe(fd_pipe_out);
close_pipe(fd_pipe_err);
+++ /dev/null
-/**
- * collectd - src/lvm.c
- * Copyright (C) 2013 Chad Malfait
- * Copyright (C) 2014 Carnegie Mellon University
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors:
- * Chad Malfait <malfaitc at yahoo.com>
- * Benjamin Gilbert <bgilbert at backtick.net>
- **/
-
-#include "collectd.h"
-
-#include "plugin.h"
-#include "utils/common/common.h"
-
-#include <lvm2app.h>
-
-#ifdef HAVE_SYS_CAPABILITY_H
-#include <sys/capability.h>
-#endif /* HAVE_SYS_CAPABILITY_H */
-
-#define NO_VALUE UINT64_MAX
-#define PERCENT_SCALE_FACTOR 1e-8
-
-static uint64_t get_lv_property_int(lv_t lv, char const *property) {
- lvm_property_value_t v;
-
- v = lvm_lv_get_property(lv, property);
- if (!v.is_valid || !v.is_integer)
- return NO_VALUE;
- /* May be NO_VALUE if @property does not apply to this LV */
- return v.value.integer;
-}
-
-static char const *get_lv_property_string(lv_t lv, char const *property) {
- lvm_property_value_t v;
-
- v = lvm_lv_get_property(lv, property);
- if (!v.is_valid || !v.is_string)
- return NULL;
- return v.value.string;
-}
-
-static void lvm_submit(char const *plugin_instance, char const *type_instance,
- uint64_t ivalue) {
- value_list_t vl = VALUE_LIST_INIT;
-
- vl.values = &(value_t){.gauge = (gauge_t)ivalue};
- vl.values_len = 1;
-
- sstrncpy(vl.plugin, "lvm", sizeof(vl.plugin));
- sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
- sstrncpy(vl.type, "df_complex", sizeof(vl.type));
- sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
-
- plugin_dispatch_values(&vl);
-}
-
-static void report_lv_utilization(lv_t lv, char const *vg_name,
- char const *lv_name, uint64_t lv_size,
- char const *used_percent_property) {
- uint64_t used_percent_unscaled;
- uint64_t used_bytes;
- char plugin_instance[DATA_MAX_NAME_LEN];
-
- used_percent_unscaled = get_lv_property_int(lv, used_percent_property);
- if (used_percent_unscaled == NO_VALUE)
- return;
- used_bytes = lv_size * (used_percent_unscaled * PERCENT_SCALE_FACTOR);
-
- ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-%s", vg_name,
- lv_name);
- lvm_submit(plugin_instance, "used", used_bytes);
- lvm_submit(plugin_instance, "free", lv_size - used_bytes);
-}
-
-static void report_thin_pool_utilization(lv_t lv, char const *vg_name,
- uint64_t lv_size) {
- char const *data_lv;
- char const *metadata_lv;
- uint64_t metadata_size;
-
- data_lv = get_lv_property_string(lv, "data_lv");
- metadata_lv = get_lv_property_string(lv, "metadata_lv");
- metadata_size = get_lv_property_int(lv, "lv_metadata_size");
- if (data_lv == NULL || metadata_lv == NULL || metadata_size == NO_VALUE)
- return;
-
- report_lv_utilization(lv, vg_name, data_lv, lv_size, "data_percent");
- report_lv_utilization(lv, vg_name, metadata_lv, metadata_size,
- "metadata_percent");
-}
-
-static void vg_read(vg_t vg, char const *vg_name) {
- struct dm_list *lvs;
- struct lvm_lv_list *lvl;
- char const *name;
- char const *attrs;
- uint64_t size;
-
- lvm_submit(vg_name, "free", lvm_vg_get_free_size(vg));
-
- lvs = lvm_vg_list_lvs(vg);
- if (!lvs) {
- /* no VGs are defined, which is not an error per se */
- return;
- }
-
- dm_list_iterate_items(lvl, lvs) {
- name = lvm_lv_get_name(lvl->lv);
- attrs = get_lv_property_string(lvl->lv, "lv_attr");
- size = lvm_lv_get_size(lvl->lv);
- if (name == NULL || attrs == NULL || size == NO_VALUE)
- continue;
-
- /* Condition on volume type. We want the reported sizes in the
- volume group to sum to the size of the volume group, so we ignore
- virtual volumes. */
- switch (attrs[0]) {
- case 's':
- case 'S':
- /* Snapshot. Also report used/free space. */
- report_lv_utilization(lvl->lv, vg_name, name, size, "data_percent");
- break;
- case 't':
- /* Thin pool virtual volume. We report the underlying data
- and metadata volumes, not this one. Report used/free
- space, then ignore. */
- report_thin_pool_utilization(lvl->lv, vg_name, size);
- continue;
- case 'v':
- /* Virtual volume. Ignore. */
- continue;
- case 'V':
- /* Thin volume or thin snapshot. Ignore. */
- continue;
- }
- lvm_submit(vg_name, name, size);
- }
-}
-
-static int lvm_read(void) {
- lvm_t lvm;
- struct dm_list *vg_names;
- struct lvm_str_list *name_list;
-
- lvm = lvm_init(NULL);
- if (!lvm) {
- ERROR("lvm plugin: lvm_init failed.");
- return -1;
- }
-
- vg_names = lvm_list_vg_names(lvm);
- if (!vg_names) {
- ERROR("lvm plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm));
- lvm_quit(lvm);
- return -1;
- }
-
- dm_list_iterate_items(name_list, vg_names) {
- vg_t vg;
-
- vg = lvm_vg_open(lvm, name_list->str, "r", 0);
- if (!vg) {
- ERROR("lvm plugin: lvm_vg_open (%s) failed: %s", name_list->str,
- lvm_errmsg(lvm));
- continue;
- }
-
- vg_read(vg, name_list->str);
- lvm_vg_close(vg);
- }
-
- lvm_quit(lvm);
- return 0;
-} /*lvm_read */
-
-static int c_lvm_init(void) {
-#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SYS_ADMIN)
- if (check_capability(CAP_SYS_ADMIN) != 0) {
- if (getuid() == 0)
- WARNING("lvm plugin: Running collectd as root, but the "
- "CAP_SYS_ADMIN capability is missing. The plugin's read "
- "function will probably fail. Is your init system dropping "
- "capabilities?");
- else
- WARNING("lvm plugin: collectd doesn't have the CAP_SYS_ADMIN "
- "capability. If you don't want to run collectd as root, try "
- "running \"setcap cap_sys_admin=ep\" on the collectd binary.");
- }
-#endif
- return 0;
-}
-
-void module_register(void) {
- plugin_register_init("lvm", c_lvm_init);
- plugin_register_read("lvm", lvm_read);
-} /* void module_register */
};
for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
- char buffer[32];
+ char buffer[32] = {0};
- strncpy(buffer, cases[i].str, sizeof(buffer));
+ strncpy(buffer, cases[i].str, sizeof(buffer) - 1);
OK(escape_slashes(buffer, sizeof(buffer)) == 0);
EXPECT_EQ_STR(cases[i].want, buffer);
}
};
for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
- char buffer[16];
+ char buffer[16] = {0};
- strncpy(buffer, cases[i].str, sizeof(buffer));
+ strncpy(buffer, cases[i].str, sizeof(buffer) - 1);
OK(escape_string(buffer, sizeof(buffer)) == 0);
EXPECT_EQ_STR(cases[i].want, buffer);
}
}
DEF_TEST(strunescape) {
- char buffer[16];
+ char buffer[32] = {0};
int status;
- strncpy(buffer, "foo\\tbar", sizeof(buffer));
+ strncpy(buffer, "foo\\tbar", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status == 0);
EXPECT_EQ_STR("foo\tbar", buffer);
- strncpy(buffer, "\\tfoo\\r\\n", sizeof(buffer));
+ strncpy(buffer, "\\tfoo\\r\\n", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status == 0);
EXPECT_EQ_STR("\tfoo\r\n", buffer);
- strncpy(buffer, "With \\\"quotes\\\"", sizeof(buffer));
+ strncpy(buffer, "With \\\"quotes\\\"", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status == 0);
EXPECT_EQ_STR("With \"quotes\"", buffer);
/* Backslash before null byte */
- strncpy(buffer, "\\tbackslash end\\", sizeof(buffer));
+ strncpy(buffer, "\\tbackslash end\\", sizeof(buffer) - 1);
status = strunescape(buffer, sizeof(buffer));
OK(status != 0);
EXPECT_EQ_STR("\tbackslash end", buffer);
return 0;
/* Backslash at buffer end */
- strncpy(buffer, "\\t3\\56", sizeof(buffer));
+ strncpy(buffer, "\\t3\\56", sizeof(buffer) - 1);
status = strunescape(buffer, 4);
OK(status != 0);
OK(buffer[0] == '\t');