Skip to content

Commit ba7b84c

Browse files
authored
Merge pull request #1351 from jan-cerny/latest_warnings
Fix some of compiler warnings
2 parents d66e786 + 5b056bb commit ba7b84c

16 files changed

+57
-34
lines changed

src/DS/rds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ static int ds_rds_create_from_dom(xmlDocPtr* ret, xmlDocPtr sds_doc, xmlDocPtr t
713713
}
714714

715715
counter = 0;
716-
while (ds_sds_find_component_ref(xmlDocGetRootElement(sds_res_node)->children, tailoring_component_ref_id) != NULL) {
716+
while (ds_sds_find_component_ref(xmlDocGetRootElement((xmlDocPtr) sds_res_node)->children, tailoring_component_ref_id) != NULL) {
717717
free(tailoring_component_ref_id);
718718
tailoring_component_ref_id = oscap_sprintf("scap_org.open-scap_cref_%s_tailoring%03d", mangled_tailoring_filepath, counter++);
719719
}
@@ -734,9 +734,9 @@ static int ds_rds_create_from_dom(xmlDocPtr* ret, xmlDocPtr sds_doc, xmlDocPtr t
734734
xmlNodePtr checklists_element = NULL;
735735
xmlNodePtr datastream_element = node_get_child_element(sds_res_node, "data-stream");
736736
if (datastream_element == NULL) {
737-
datastream_element = xmlNewNode(sds_ns, "data-stream");
737+
datastream_element = xmlNewNode(sds_ns, BAD_CAST "data-stream");
738738
xmlAddChild(sds_res_node, datastream_element);
739-
checklists_element = xmlNewNode(sds_ns, "checklists");
739+
checklists_element = xmlNewNode(sds_ns, BAD_CAST "checklists");
740740
xmlAddChild(datastream_element, checklists_element);
741741
}
742742
else {
@@ -804,7 +804,7 @@ struct oscap_source *ds_rds_create_source(struct oscap_source *sds_source, struc
804804

805805
xmlDoc *tailoring_doc = NULL;
806806
char *tailoring_doc_timestamp = NULL;
807-
char *tailoring_filepath = NULL;
807+
const char *tailoring_filepath = NULL;
808808
if (tailoring_source) {
809809
tailoring_doc = oscap_source_get_xmlDoc(tailoring_source);
810810
if (tailoring_doc == NULL) {

src/OVAL/oval_defModel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct oval_definition_model *oval_definition_model_new()
8484
return newmodel;
8585
}
8686

87-
typedef void (*_oval_clone_func) (void *, struct oval_definition_model *);
87+
typedef void *(*_oval_clone_func) (void *, struct oval_definition_model *);
8888

8989
static void _oval_definition_model_clone(struct oval_string_map *oldmap,
9090
struct oval_definition_model *newmodel,

src/OVAL/oval_generator.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,20 @@ void oval_generator_update_timestamp(struct oval_generator *generator)
153153
{
154154
time_t et;
155155
struct tm *lt;
156-
char timestamp[] = "yyyy-mm-ddThh:mm:ss";
157156

158157
time(&et);
159158
lt = localtime(&et);
160-
snprintf(timestamp, sizeof(timestamp), "%4d-%02d-%02dT%02d:%02d:%02d",
159+
int timestamp_size = snprintf(NULL, 0, "%4d-%02d-%02dT%02d:%02d:%02d",
160+
1900 + lt->tm_year, 1 + lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
161+
if (timestamp_size < 0) {
162+
return;
163+
}
164+
timestamp_size++; // +1 for terminating '\0' byte
165+
char *timestamp = malloc(timestamp_size);
166+
snprintf(timestamp, timestamp_size, "%4d-%02d-%02dT%02d:%02d:%02d",
161167
1900 + lt->tm_year, 1 + lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);
162168
oval_generator_set_timestamp(generator, timestamp);
169+
free(timestamp);
163170
}
164171

165172
void oval_generator_add_platform_schema_version(struct oval_generator *generator, const char *platform, const char *schema_version)

src/OVAL/oval_sysModel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct oval_syschar_model *oval_syschar_model_new(struct oval_definition_model *
9191
return newmodel;
9292
}
9393

94-
typedef void (*_oval_clone_func) (void *, struct oval_syschar_model *);
94+
typedef void *(*_oval_clone_func) (void *, struct oval_syschar_model *);
9595

9696
static void _oval_syschar_model_clone(struct oval_string_map *oldmap,
9797
struct oval_syschar_model *newmodel, _oval_clone_func cloner)

src/OVAL/probes/SEAP/sexp-manip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name)
19181918
SEXP_val_t v_dsc;
19191919
SEXP_t *s_nth;
19201920

1921-
if (list == NULL || name == NULL) {
1921+
if (list == NULL) {
19221922
errno = EFAULT;
19231923
return -1;
19241924
}

src/OVAL/probes/probe/input_handler.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
#include "input_handler.h"
3939
#include "common/compat_pthread_barrier.h"
4040

41+
static void pthread_attr_cleanup_handler(void *arg)
42+
{
43+
pthread_attr_destroy(arg);
44+
}
45+
4146
/*
4247
* The input handler waits for incomming eval requests and either returns
4348
* a result immediately if it is found in the result cache or spawns a new
@@ -74,7 +79,7 @@ void *probe_input_handler(void *arg)
7479
return (NULL);
7580
}
7681

77-
pthread_cleanup_push((void(*)(void *))pthread_attr_destroy, (void *)&pth_attr);
82+
pthread_cleanup_push(pthread_attr_cleanup_handler, (void *)&pth_attr);
7883

7984
switch (errno = pthread_barrier_wait(&OSCAP_GSYM(th_barrier)))
8085
{

src/OVAL/probes/unix/linux/inetlisteningservers_probe.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,25 @@ static int collect_process_info(llist *l)
249249
}
250250
// For each file in the fd dir...
251251
while (( ent = readdir(f) )) {
252-
char line[256], ln[256], *s, *e;
252+
char line[256], *s, *e;
253253
unsigned long inode;
254254
lnode node;
255255
int lnlen;
256256

257257
if (ent->d_name[0] == '.')
258258
continue;
259-
snprintf(ln, 256, "%s/%s", buf, ent->d_name);
260-
if ((lnlen = readlink(ln, line, sizeof(line)-1)) < 0)
259+
int pathname_len = snprintf(NULL, 0, "%s/%s", buf, ent->d_name);
260+
if (pathname_len < 0) {
261261
continue;
262+
}
263+
pathname_len++; // +1 for terminating '\0'
264+
char *pathname = malloc(pathname_len);
265+
snprintf(pathname, pathname_len, "%s/%s", buf, ent->d_name);
266+
lnlen = readlink(pathname, line, sizeof(line) - 1);
267+
free(pathname);
268+
if (lnlen < 0) {
269+
continue;
270+
}
262271
line[lnlen] = 0;
263272

264273
// Only look at the socket entries

src/OVAL/probes/unix/linux/rpmverify_probe.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ static int rpmverify_collect(probe_ctx *ctx,
219219
return (ret);
220220
}
221221

222-
void rpmverify_probe_preload()
223-
{
224-
rpmLibsPreload();
225-
}
226-
227222
int rpmverify_probe_offline_mode_supported()
228223
{
229224
// TODO: Switch this to OFFLINE_MODE_OWN once rpmtsSetRootDir is fully supported by librpm

src/OVAL/probes/unix/linux/rpmverifyfile_probe.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ static int rpmverify_collect(probe_ctx *ctx,
303303
return (ret);
304304
}
305305

306-
void rpmverifyfile_probe_preload()
307-
{
308-
rpmLibsPreload();
309-
}
310-
311306
int rpmverifyfile_probe_offline_mode_supported()
312307
{
313308
// TODO: Switch this to OFFLINE_MODE_OWN once rpmtsSetRootDir is fully supported by librpm

src/XCCDF/benchmark.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,7 @@ char *xccdf_benchmark_gen_id(struct xccdf_benchmark *benchmark, xccdf_type_t typ
687687
assert(prefix != NULL);
688688

689689
const char *fmt = "%s%03d";
690-
char foo[2];
691-
int length = snprintf(foo, 1, fmt, prefix, 0);
690+
int length = snprintf(NULL, 0, fmt, prefix, 0);
692691
if (length < 0)
693692
return NULL;
694693
length++;

0 commit comments

Comments
 (0)