#include #include #include #include #include #include typedef struct creds creds_t; typedef struct creds { char name[16]; void (*welcome)(void); } creds_t; static creds_t *creds; /* internal prototypes */ static void login(void); static void s3cr3t(void); /* entry point */ // ./mixed01 aaaaaaaaaaaaaaaaa 65536 int main(int argc, char **argv) { if (argc < 3) { printf("usage: %s \n", argv[0]); return -1; } int32_t size = atoi(argv[2]); uint16_t s = size; creds = (creds_t *)calloc(1, sizeof(creds_t)); if (!creds) { perror("calloc"); return -1; } if (s >= sizeof(creds->name)) { fprintf(stderr, "length exceeds buffer size\n"); free(creds); return -1; } creds->welcome = login; snprintf(creds->name, size + 1, "%s", argv[1]); creds->welcome(); free(creds); return 0; } /* internal function definitions */ static void login(void) { printf("Hello %s.\n", creds->name); } static void s3cr3t(void) { printf("You've gathered secret material!\n"); }