Fix format-trunctation warning from gcc 9 19/220919/1 accepted/tizen/unified/20191227.142715 submit/tizen/20191226.234511
authorSemun Lee <semun.lee@samsung.com>
Thu, 26 Dec 2019 02:08:39 +0000 (11:08 +0900)
committerSemun Lee <semun.lee@samsung.com>
Thu, 26 Dec 2019 02:08:39 +0000 (11:08 +0900)
Change-Id: Ia1edce376a4c9ef1521a0d1f1837324df27517a3
Signed-off-by: Semun Lee <semun.lee@samsung.com>
src/tethering.c

index 46c81681b985b8c0c59b04f63339ad94f71fb78d..0a132a76b593d8c95eed9094398250a0409b454e 100755 (executable)
@@ -14,6 +14,7 @@
 * limitations under the License.
 */
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -4076,8 +4077,8 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port,
        GVariant *parameters;
        GError *error = NULL;
        guint result;
-       char cmd[MAX_BUF_SIZE] = { 0, };
        char *list = NULL;
+       int ret;
 
        __tethering_h *th = (__tethering_h *)tethering;
 
@@ -4104,18 +4105,17 @@ API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port,
        g_variant_unref(parameters);
 
        if (allow)
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
+               ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
        else
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
-
-       DBG("cmd:%s", cmd);
+               ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
 
-       list = strdup(cmd);
-       if (list == NULL) {
-               ERR("strdup failed\n"); //LCOV_EXCL_LINE
+       if (ret == -1 || list == NULL) {
+               ERR("asprintf failed\n"); //LCOV_EXCL_LINE
                return TETHERING_ERROR_OUT_OF_MEMORY;
        }
 
+       DBG("cmd:%s", list);
+
        port_filtering = g_slist_append(port_filtering, list);
 
        return TETHERING_ERROR_NONE;
@@ -4134,8 +4134,8 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int
        GVariant *parameters;
        GError *error = NULL;
        guint result;
-       char cmd[MAX_BUF_SIZE] = { 0, };
        char *list = NULL;
+       int ret;
 
        __tethering_h *th = (__tethering_h *)tethering;
 
@@ -4162,18 +4162,17 @@ API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int
        g_variant_unref(parameters);
 
        if (allow)
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
+               ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
        else
-               snprintf(cmd, sizeof(cmd), "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
-
-       DBG("cmd:%s", cmd);
+               ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
 
-       list = strdup(cmd);
-       if (list == NULL) {
-               ERR("strdup failed\n"); //LCOV_EXCL_LINE
+       if (ret == -1 || list == NULL) {
+               ERR("asprintf failed\n"); //LCOV_EXCL_LINE
                return TETHERING_ERROR_OUT_OF_MEMORY;
        }
 
+       DBG("cmd:%s", list);
+
        custom_port_filtering = g_slist_append(custom_port_filtering, list);
 
        return TETHERING_ERROR_NONE;