hal: fix null pointer references and data initialization errors
- add null pointer check and initialize uninitialized variables
CRs-Fixed: 2312146
Change-Id: I5f260b327492e1373ed143dd8dcf243154fd7818
diff --git a/hal/audio_extn/soundtrigger.c b/hal/audio_extn/soundtrigger.c
index 83fb72a..48b0c5b 100644
--- a/hal/audio_extn/soundtrigger.c
+++ b/hal/audio_extn/soundtrigger.c
@@ -677,7 +677,9 @@
st_dev->sthal_prop_api_version = 0;
status = 0; /* passthru for backward compability */
} else {
- st_dev->sthal_prop_api_version = *(int*)sthal_prop_api_version;
+ if (sthal_prop_api_version != NULL) {
+ st_dev->sthal_prop_api_version = *(int*)sthal_prop_api_version;
+ }
if (MAJOR_VERSION(st_dev->sthal_prop_api_version) !=
MAJOR_VERSION(STHAL_PROP_API_CURRENT_VERSION)) {
ALOGE("%s: Incompatible API versions ahal:0x%x != sthal:0x%x",
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index f31991a..41f76c6 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2021,10 +2021,10 @@
struct stream_out stream_out;
audio_usecase_t hfp_ucid;
int status = 0;
- audio_devices_t audio_device;
- audio_channel_mask_t channel_mask;
- int sample_rate;
- int acdb_id;
+ audio_devices_t audio_device = AUDIO_DEVICE_NONE;
+ audio_channel_mask_t channel_mask = AUDIO_CHANNEL_NONE;
+ int sample_rate = 0;
+ int acdb_id = 0;
ALOGD("%s for use case (%s)", __func__, use_case_table[uc_id]);
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index d05c5ed..82fafc7 100755
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -5113,7 +5113,8 @@
platform->spkr_ch_map->num_ch = num_ch;
for (i = 0; i < num_ch; i++) {
opts = strtok_r(NULL, ", ", &test_r);
- platform->spkr_ch_map->chmap[i] = strtoul(opts, NULL, 16);
+ if (opts != NULL)
+ platform->spkr_ch_map->chmap[i] = strtoul(opts, NULL, 16);
}
}
str_parms_del(parms, AUDIO_PARAMETER_KEY_SPKR_DEVICE_CHMAP);
diff --git a/qahw_api/test/qahw_multi_record_test.c b/qahw_api/test/qahw_multi_record_test.c
index 18508b5..8168ccc 100644
--- a/qahw_api/test/qahw_multi_record_test.c
+++ b/qahw_api/test/qahw_multi_record_test.c
@@ -926,10 +926,10 @@
/* Caution: Below ADL log shouldnt be altered without notifying automation APT since it used
* for automation testing
*/
- fprintf(log_file, "\n ADL: Done with hal record test \n");
- if (log_file != stdout) {
- fprintf(stdout, "\n ADL: Done with hal record test \n");
- if (log_file) {
+ if (log_file != NULL) {
+ fprintf(log_file, "\n ADL: Done with hal record test \n");
+ if (log_file != stdout) {
+ fprintf(stdout, "\n ADL: Done with hal record test \n");
fclose(log_file);
log_file = NULL;
}
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index b410006..af3cc57 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -2331,6 +2331,8 @@
fprintf(stderr, " In Device config \n");
send_device_config = true;
+ memset(&device_cfg_params, 0, sizeof(struct qahw_device_cfg_param));
+
//Read Sample Rate
if (optind < argc && *argv[optind] != '-') {
device_cfg_params.sample_rate = atoi(optarg);