refactor: sprintf -> snprint, strncpy -> strlcpy
This commit is contained in:
+33
-31
@@ -21,7 +21,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
config_file_get_int(config, "SELECT_PAGE_COUNT", 0);
|
||||
|
||||
for (i = 0; i < state_config.select_page_codes.length; i++) {
|
||||
sprintf(name, "SELECT_PAGE_%d", i + 1);
|
||||
snprintf(name, STR_LEN, "SELECT_PAGE_%d", i + 1);
|
||||
state_config.select_page_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
config_file_get_int(config, "SELECT_ITEM_COUNT", 0);
|
||||
|
||||
for (i = 0; i < state_config.select_item_codes.length; i++) {
|
||||
sprintf(name, "SELECT_ITEM_%d", i + 1);
|
||||
snprintf(name, STR_LEN, "SELECT_ITEM_%d", i + 1);
|
||||
state_config.select_item_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
config_file_get_int(config, "FRAG_COUNT", 1);
|
||||
|
||||
for (i = 0; i < state_config.select_frag_codes.length; i++) {
|
||||
sprintf(name, "SELECT_FRAG_%d", i + 1);
|
||||
snprintf(name, STR_LEN, "SELECT_FRAG_%d", i + 1);
|
||||
state_config.select_frag_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < state_config.midi_active_counts.length; i++) {
|
||||
sprintf(name, "MIDI_%d_ACTIVE_COUNT", i + 1);
|
||||
snprintf(name, STR_LEN, "MIDI_%d_ACTIVE_COUNT", i + 1);
|
||||
state_config.midi_active_counts.values[i] =
|
||||
config_file_get_int(config, name, 1);
|
||||
state_config.midi_active_offsets.values[i] = count;
|
||||
@@ -66,7 +66,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
|
||||
for (i = 0; i < state_config.midi_active_counts.length; i++) {
|
||||
for (j = 0; j < state_config.midi_active_counts.values[i]; j++) {
|
||||
sprintf(name, "MIDI_%d_ACTIVE_%d", i + 1, j + 1);
|
||||
snprintf(name, STR_LEN, "MIDI_%d_ACTIVE_%d", i + 1, j + 1);
|
||||
state_config.midi_active_codes
|
||||
.values[state_config.midi_active_offsets.values[i] + j] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
@@ -76,7 +76,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
count = 0;
|
||||
offset = 0;
|
||||
for (i = 0; i < state_config.midi_counts.length; i++) {
|
||||
sprintf(name, "MIDI_%d_COUNT", i + 1);
|
||||
snprintf(name, STR_LEN, "MIDI_%d_COUNT", i + 1);
|
||||
state_config.midi_counts.values[i] = config_file_get_int(config, name, 0);
|
||||
state_config.midi_offsets.values[i] = count;
|
||||
state_config.values_offsets.values[i] = offset;
|
||||
@@ -90,15 +90,15 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
for (i = 0; i < state_config.midi_counts.length; i++) {
|
||||
offset = state_config.midi_offsets.values[i];
|
||||
for (j = 0; j < state_config.midi_counts.values[i]; j++) {
|
||||
sprintf(name, "MIDI_%d_%d_X", i + 1, j + 1);
|
||||
snprintf(name, STR_LEN, "MIDI_%d_%d_X", i + 1, j + 1);
|
||||
state_config.midi_codes.values[(offset + j) * 3] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
|
||||
sprintf(name, "MIDI_%d_%d_Y", i + 1, j + 1);
|
||||
snprintf(name, STR_LEN, "MIDI_%d_%d_Y", i + 1, j + 1);
|
||||
state_config.midi_codes.values[(offset + j) * 3 + 1] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
|
||||
sprintf(name, "MIDI_%d_%d_Z", i + 1, j + 1);
|
||||
snprintf(name, STR_LEN, "MIDI_%d_%d_Z", i + 1, j + 1);
|
||||
state_config.midi_codes.values[(offset + j) * 3 + 2] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ StateConfig state_parse_config(ConfigFile config) {
|
||||
config_file_get_int(config, "FADER_COUNT", 0);
|
||||
|
||||
for (i = 0; i < state_config.fader_codes.length; i++) {
|
||||
sprintf(name, "FADER_%d", i + 1);
|
||||
snprintf(name, STR_LEN, "FADER_%d", i + 1);
|
||||
state_config.fader_codes.values[i] =
|
||||
config_file_get_int(config, name, UNSET_MIDI_CODE);
|
||||
}
|
||||
@@ -338,26 +338,26 @@ static void state_load(SharedContext *context, StateConfig state_config,
|
||||
context->selected = config_file_get_int(saved_state, "selected", 0);
|
||||
|
||||
for (i = 0; i < context->state.length; i++) {
|
||||
sprintf(key, "seed_%d", i);
|
||||
snprintf(key, STR_LEN, "seed_%d", i);
|
||||
context->seeds[i] =
|
||||
config_file_get_int(saved_state, key, context->seeds[i]);
|
||||
sprintf(key, "state_%d", i);
|
||||
snprintf(key, STR_LEN, "state_%d", i);
|
||||
context->state.values[i] = config_file_get_int(saved_state, key, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config.midi_active_counts.length; i++) {
|
||||
sprintf(key, "active_%d", i);
|
||||
snprintf(key, STR_LEN, "active_%d", i);
|
||||
context->active[i] = config_file_get_int(saved_state, key, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config.midi_codes.length; i++) {
|
||||
sprintf(key, "value_%d_x", i);
|
||||
snprintf(key, STR_LEN, "value_%d_x", i);
|
||||
context->values[i][0] =
|
||||
(float)config_file_get_int(saved_state, key, 0) / MIDI_MAX;
|
||||
sprintf(key, "value_%d_y", i);
|
||||
snprintf(key, STR_LEN, "value_%d_y", i);
|
||||
context->values[i][1] =
|
||||
(float)config_file_get_int(saved_state, key, 0) / MIDI_MAX;
|
||||
sprintf(key, "value_%d_z", i);
|
||||
snprintf(key, STR_LEN, "value_%d_z", i);
|
||||
context->values[i][2] =
|
||||
(float)config_file_get_int(saved_state, key, 0) / MIDI_MAX;
|
||||
}
|
||||
@@ -416,29 +416,31 @@ void state_save(SharedContext *context, StateConfig state_config,
|
||||
|
||||
lines.length = 0;
|
||||
|
||||
sprintf(lines.values[lines.length++], "tempo=%d",
|
||||
(unsigned int)context->tempo.tempo);
|
||||
sprintf(lines.values[lines.length++], "page=%d", context->page);
|
||||
sprintf(lines.values[lines.length++], "selected=%d", context->selected);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "tempo=%d",
|
||||
(unsigned int)context->tempo.tempo);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "page=%d", context->page);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "selected=%d",
|
||||
context->selected);
|
||||
|
||||
for (i = 0; i < context->state.length; i++) {
|
||||
sprintf(lines.values[lines.length++], "seed_%d=%d", i, context->seeds[i]);
|
||||
sprintf(lines.values[lines.length++], "state_%d=%d", i,
|
||||
context->state.values[i]);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "seed_%d=%d", i,
|
||||
context->seeds[i]);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "state_%d=%d", i,
|
||||
context->state.values[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config.midi_active_counts.length; i++) {
|
||||
sprintf(lines.values[lines.length++], "active_%d=%d", i,
|
||||
context->active[i]);
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "active_%d=%d", i,
|
||||
context->active[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < state_config.midi_codes.length; i++) {
|
||||
sprintf(lines.values[lines.length++], "value_%d_x=%d", i,
|
||||
(unsigned int)(context->values[i][0] * MIDI_MAX));
|
||||
sprintf(lines.values[lines.length++], "value_%d_y=%d", i,
|
||||
(unsigned int)(context->values[i][1] * MIDI_MAX));
|
||||
sprintf(lines.values[lines.length++], "value_%d_z=%d", i,
|
||||
(unsigned int)(context->values[i][2] * MIDI_MAX));
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "value_%d_x=%d", i,
|
||||
(unsigned int)(context->values[i][0] * MIDI_MAX));
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "value_%d_y=%d", i,
|
||||
(unsigned int)(context->values[i][1] * MIDI_MAX));
|
||||
snprintf(lines.values[lines.length++], STR_LEN, "value_%d_z=%d", i,
|
||||
(unsigned int)(context->values[i][2] * MIDI_MAX));
|
||||
}
|
||||
|
||||
file_write(state_file, lines);
|
||||
|
||||
Reference in New Issue
Block a user