Skip to content

Commit

Permalink
CodeQL fixes (#47)
Browse files Browse the repository at this point in the history
* fix codeql issues and configured codeql
  • Loading branch information
brtnfld authored Dec 6, 2024
1 parent a54d4cb commit 57a6a26
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .github/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
query-filters:
- exclude:
id: 3rdparty
- exclude:
id: cpp/toctou-race-condition
- exclude:
id: cpp/short-global-name
- exclude:
# See: https://codeql.github.com/codeql-query-help/cpp/cpp-commented-out-code/
id: cpp/commented-out-code
paths:
- 'src'
paths-ignore:
- 'test'

20 changes: 7 additions & 13 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ jobs:
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ubuntu-latest
#runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
#actions: read
#contents: read

strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -94,30 +89,29 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
languages: c-cpp
build-mode: manual
config-file: ./.github/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# For more details on CodeQL's query packs, refer to:
#https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: +security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- name: Async VOL,build and test
- name: Async VOL -- Build and Test
shell: bash
run: |
cd build
make && make install
ctest -V -E async_test_parallel5 .
ctest -V .
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
category: "/language:c-cpp"
32 changes: 30 additions & 2 deletions src/h5_async_vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,14 @@ async_instance_init(int backing_thread_count)
char fname[128];
sprintf(fname, "async.log.%d", aid->mpi_rank);
fout_g = fopen(fname, "w");
if (fout_g == NULL) {
fprintf(fout_g, " [ASYNC VOL ERROR] with opening %s\n", fname);
free(progress_xstreams);
free(progress_scheds);
free(aid);
hg_ret = -1;
goto done;
}
}
done:
abt_ret = ABT_mutex_unlock(async_instance_mutex_g);
Expand Down Expand Up @@ -19621,7 +19629,11 @@ H5VL_async_new_obj(void *under_obj, hid_t under_vol_id)
{
H5VL_async_t *new_obj;

new_obj = (H5VL_async_t *)calloc(1, sizeof(H5VL_async_t));
new_obj = (H5VL_async_t *)calloc(1, sizeof(H5VL_async_t));
if (new_obj == NULL) {
fprintf(fout_g, " [ASYNC VOL ERROR] with allocation in %s\n", __func__);
return NULL;
}
new_obj->magic = ASYNC_MAGIC;
new_obj->under_object = under_obj;
new_obj->under_vol_id = under_vol_id;
Expand Down Expand Up @@ -19703,6 +19715,10 @@ H5VL_async_info_copy(const void *_info)

/* Allocate new VOL info struct for the async connector */
new_info = (H5VL_async_info_t *)calloc(1, sizeof(H5VL_async_info_t));
if (new_info == NULL) {
fprintf(fout_g, " [ASYNC VOL ERROR] with allocation in %s\n", __func__);
return NULL;
}

/* Increment reference count on underlying VOL ID, and copy the VOL info */
new_info->under_vol_id = info->under_vol_id;
Expand Down Expand Up @@ -19861,6 +19877,10 @@ H5VL_async_str_to_info(const char *str, void **_info)
#endif

/* Retrieve the underlying VOL connector value and info */
if (sscanf(str, "under_vol=%u;", &under_vol_value) != 1) {
fprintf(fout_g, " [ASYNC VOL ERROR] in %s\n", __func__);
return -1; /* Failed to parse the VOL connector input string */
}
sscanf(str, "under_vol=%u;", &under_vol_value);
under_vol_id = H5VLregister_connector_by_value((H5VL_class_value_t)under_vol_value, H5P_DEFAULT);
if (strstr(str, "[") && strstr(str, "]")) {
Expand All @@ -19886,7 +19906,11 @@ H5VL_async_str_to_info(const char *str, void **_info)
} /* end else */

/* Allocate new async VOL connector info and set its fields */
info = (H5VL_async_info_t *)calloc(1, sizeof(H5VL_async_info_t));
info = (H5VL_async_info_t *)calloc(1, sizeof(H5VL_async_info_t));
if (info == NULL) {
fprintf(fout_g, " [ASYNC VOL ERROR] with allocation in %s\n", __func__);
return -1;
}
info->under_vol_id = under_vol_id;
info->under_vol_info = under_vol_info;

Expand Down Expand Up @@ -19944,6 +19968,10 @@ H5VL_async_get_wrap_ctx(const void *obj, void **wrap_ctx)

/* Allocate new VOL object wrapping context for the async connector */
new_wrap_ctx = (H5VL_async_wrap_ctx_t *)calloc(1, sizeof(H5VL_async_wrap_ctx_t));
if (new_wrap_ctx == NULL) {
fprintf(fout_g, " [ASYNC VOL ERROR] with allocation in %s\n", __func__);
return -1;
}

if (o_async->under_vol_id > 0) {
under_vol_id = o_async->under_vol_id;
Expand Down
3 changes: 1 addition & 2 deletions test/async_test_multifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ main(int argc, char *argv[])
sleep(sleeptime);

gettimeofday(&t0, 0);

sprintf(file_name, "%s/test_%d.h5", fpath, ifile);
snprintf(file_name, sizeof(file_name), "%s/test_%d.h5", fpath, ifile);
file_id = H5Fcreate_async(file_name, H5F_ACC_TRUNC, H5P_DEFAULT, async_fapl, es_id);
if (file_id < 0) {
fprintf(stderr, "Error with file create\n");
Expand Down
2 changes: 1 addition & 1 deletion test/async_test_parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ main(int argc, char *argv[])
goto done;
}

offset[0] = my_rank * (DIMLEN / proc_num);
offset[0] = (hsize_t)my_rank * (DIMLEN / proc_num);
offset[1] = 0;
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, my_size, NULL);

Expand Down
2 changes: 1 addition & 1 deletion test/async_test_parallel2.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ main(int argc, char *argv[])
goto done;
}

offset[0] = my_rank * (DIMLEN / proc_num);
offset[0] = (hsize_t)my_rank * (DIMLEN / proc_num);
offset[1] = 0;
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, my_size, NULL);

Expand Down
2 changes: 1 addition & 1 deletion test/async_test_parallel3.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ main(int argc, char *argv[])
goto done;
}

offset[0] = my_rank * (DIMLEN / proc_num);
offset[0] = (hsize_t)my_rank * (DIMLEN / proc_num);
offset[1] = 0;
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, my_size, NULL);

Expand Down
2 changes: 1 addition & 1 deletion test/async_test_parallel4.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ main(int argc, char *argv[])
goto done;
}

offset[0] = my_rank * (DIMLEN / proc_num);
offset[0] = (hsize_t)my_rank * (DIMLEN / proc_num);
offset[1] = 0;
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, my_size, NULL);

Expand Down
3 changes: 1 addition & 2 deletions test/async_test_parallel5.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ main(int argc, char *argv[])
ret = -1;
goto done;
}

offset[0] = my_rank * (DIMLEN / proc_num);
offset[0] = (hsize_t)my_rank * (DIMLEN / proc_num);
offset[1] = 0;
H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, offset, NULL, my_size, NULL);

Expand Down
1 change: 0 additions & 1 deletion test/async_test_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ main(int argc, char *argv[])
fprintf(stderr, "Error with dset 0 read %d/%d\n", data1_read[i], i);
ret = -1;
goto done;
break;
}
}
printf("Finished verification\n");
Expand Down
1 change: 0 additions & 1 deletion test/async_test_serial_event_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ main(int argc, char *argv[])
fprintf(stderr, "Error with dset 0 read %d/%d\n", data1_read[i], i);
ret = -1;
goto done;
break;
}
}
fprintf(stderr, "Finished verification\n");
Expand Down

0 comments on commit 57a6a26

Please sign in to comment.