Use safe wrappers wherever possible

This commit is contained in:
shdown
2015-08-03 12:50:50 +03:00
parent bc52fae15c
commit c85d16faa4
14 changed files with 31 additions and 52 deletions

View File

@ -103,7 +103,7 @@ static void restore_input_focus(void) {
*
*/
static uint8_t *concat_strings(char **glyphs, int max) {
uint8_t *output = calloc(max + 1, 4);
uint8_t *output = scalloc(max + 1, 4);
uint8_t *walk = output;
for (int c = 0; c < max; c++) {
printf("at %c\n", glyphs[c][0]);
@ -187,10 +187,10 @@ static void finish_input() {
/* allocate space for the output */
int inputlen = strlen(command);
char *full = calloc(1,
strlen(format) - (2 * cnt) /* format without all %s */
+ (inputlen * cnt) /* replaced %s */
+ 1); /* trailing NUL */
char *full = scalloc(strlen(format) - (2 * cnt) /* format without all %s */
+ (inputlen * cnt) /* replaced %s */
+ 1, /* trailing NUL */
1);
char *dest = full;
for (c = 0; c < len; c++) {
/* if this is not % or it is % but without a following 's',
@ -359,7 +359,7 @@ free_resources:
}
int main(int argc, char *argv[]) {
format = strdup("%s");
format = sstrdup("%s");
socket_path = getenv("I3SOCK");
char *pattern = sstrdup("pango:monospace 8");
int o, option_index = 0;
@ -381,7 +381,7 @@ int main(int argc, char *argv[]) {
switch (o) {
case 's':
FREE(socket_path);
socket_path = strdup(optarg);
socket_path = sstrdup(optarg);
break;
case 'v':
printf("i3-input " I3_VERSION);
@ -401,11 +401,11 @@ int main(int argc, char *argv[]) {
break;
case 'f':
FREE(pattern);
pattern = strdup(optarg);
pattern = sstrdup(optarg);
break;
case 'F':
FREE(format);
format = strdup(optarg);
format = sstrdup(optarg);
break;
case 'h':
printf("i3-input " I3_VERSION "\n");