-
Notifications
You must be signed in to change notification settings - Fork 3
yandere 가 더욱 집착하게 된 것이다
#60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
271c2d5
feat: prevent escapes via signals
logic-finder 33431bd
fix: exit when sigint occurs
logic-finder 0ec0b03
fix: ignore `signal` return values
logic-finder 5ba11df
fix: make it static
logic-finder 6e7a738
fix: emphasize the sigint message
logic-finder e9f8d56
fix, feat, refactor: a lot of work all in one
logic-finder 7949420
fix: prevent buffer overflow
logic-finder da999e2
fix: address the `safe_vfprintf` issue
logic-finder 3b1ca0e
fix: remove `safe_putchar` as not necessary
logic-finder 2b7d993
fix: replace an invalid format specifier
logic-finder b9af1d5
fix: rewrite `mblen_`
logic-finder 3f4fb04
fix: init `event` before installing sighandlers
logic-finder c44bdbb
fix: not reinstall signal handlers
logic-finder 1f39d22
fix: stop if `signal` fails
logic-finder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| yandere | ||
| yandere.exe | ||
| yandere.o | ||
| *.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| CC = gcc | ||
| CCFLAGS = -O -Wall -W -pedantic | ||
| CCFLAGS = -O -Wall -W -pedantic -g | ||
|
|
||
| TARGET = yandere | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #ifndef COLORCODES_H | ||
| #define COLORCODES_H | ||
|
|
||
| #define Creset "\033[0m" // color reset | ||
| #define Cemerald "\033[38;5;49;1m" // emerald | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #include "evthandlers.h" | ||
|
|
||
| extern void evthandle_default(void) { | ||
| noise(msgs[Event_default]); | ||
| printf("%s ", buf); | ||
| } | ||
|
|
||
| extern void evthandle_sigint(void) { | ||
| printf("\n\n%s\n\n", msgs[Event_sigint]); | ||
| exit(EXIT_FAILURE); /* intended */ | ||
| } | ||
|
|
||
| extern void evthandle_sigquit(void) { | ||
| noise(msgs[Event_sigquit]); | ||
| printf("%s ", buf); | ||
| } | ||
|
|
||
| extern void evthandle_sigterm(void) { | ||
| noise(msgs[Event_sigterm]); | ||
| printf("%s ", buf); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #ifndef EVTHANDLERS_H | ||
| #define EVTHANDLERS_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| # | ||
| #include "noise.h" | ||
| #include "global.h" | ||
|
|
||
| /************** | ||
| * PROTOTYPES * | ||
| **************/ | ||
| void evthandle_default(void); | ||
| void evthandle_sigint(void); | ||
| void evthandle_sigquit(void); | ||
| void evthandle_sigterm(void); | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include "fatal.h" | ||
|
|
||
| extern void fatal(const char *errmsg, const char *funcname) { | ||
| safe_fprintf( | ||
| stderr, | ||
| PROGNAME ": fatal: %s in " Cemerald "%s" Creset "\n", | ||
| errmsg, funcname | ||
| ); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
| extern void vfatal(const char *errmsg, const char *funcname, ...) { | ||
| va_list ap; | ||
|
|
||
| safe_fputs(stderr, PROGNAME ": fatal: "); | ||
|
|
||
| va_start(ap, funcname); | ||
| safe_vfprintf(stderr, errmsg, &ap); | ||
| va_end(ap); | ||
|
|
||
| safe_fprintf( | ||
| stderr, | ||
| " in " Cemerald "%s" Creset "\n", | ||
| funcname | ||
| ); | ||
|
|
||
| exit(EXIT_FAILURE); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #ifndef FATAL_H | ||
| #define FATAL_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <stdarg.h> | ||
| # | ||
| #include "global.h" | ||
| #include "wrappers.h" | ||
| #include "colorcodes.h" | ||
|
logic-finder marked this conversation as resolved.
|
||
|
|
||
| /********** | ||
| * MACROS * | ||
| **********/ | ||
| #define ERR(errmsg) fatal(errmsg, __func__) | ||
| #define VERR(errmsg, ...) vfatal(errmsg, __func__, __VA_ARGS__) | ||
|
|
||
| /************** | ||
| * PROTOTYPES * | ||
| **************/ | ||
| void fatal(const char *errmsg, const char *funcname); | ||
| void vfatal(const char *errmsg, const char *funcname, ...); | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include "global.h" | ||
|
|
||
| const char *msgs[] = { | ||
| [Event_default] = "이제 내가 싫어진 것이다?", | ||
| [Event_sigint ] = "도망갈 수 있을 거라 생각하지 마는 것이다", | ||
| [Event_sigquit] = "발버둥치지 않는 것이다", | ||
| [Event_sigterm] = "설마 도망가려는 것이다?" | ||
| }; | ||
|
|
||
| volatile sig_atomic_t event; | ||
|
|
||
| char buf[BUFMAX]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #ifndef GLOBAL_H | ||
| #define GLOBAL_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include <signal.h> | ||
|
|
||
| /********** | ||
| * MACROS * | ||
| **********/ | ||
| #define PROGNAME "yandere" | ||
| #define BUFMAX 128 | ||
|
|
||
| /************ | ||
| * TYPEDEFS * | ||
| ************/ | ||
| typedef void sighandler_t(int sig); | ||
|
|
||
| typedef enum { | ||
| Event_default, | ||
| Event_sigint, | ||
| Event_sigquit, | ||
| Event_sigterm | ||
| } event_t; | ||
|
|
||
| /******************** | ||
| * EXTERN VARIABLES * | ||
| ********************/ | ||
| extern const char *msgs[]; | ||
| extern volatile sig_atomic_t event; | ||
| extern char buf[]; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include "noise.h" | ||
|
|
||
| extern void noise(const char *msg) { | ||
| int i, k; | ||
| int rv, chlen; | ||
| bool overflow; | ||
|
|
||
| for (i = k = 0; msg[i] != '\0'; /* empty */) { | ||
| rv = rand_range(0, 6); | ||
| chlen = mblen_(msg[i]); | ||
| overflow = (k + chlen) >= (BUFMAX - 1); | ||
|
|
||
| if (overflow) break; | ||
| if (rv == 0) { /* 1/6 chance */ | ||
| buf[k++] = *("#?@" + rand_range(0, 3)); | ||
| i += chlen; | ||
| } | ||
| else for (int m = 0; m < chlen; m++) | ||
| buf[k++] = msg[i++]; | ||
| } | ||
| buf[k] = '\0'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef NOISE_H | ||
| #define NOISE_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include <stdbool.h> | ||
| # | ||
| #include "utils.h" | ||
| #include "wrappers.h" | ||
|
logic-finder marked this conversation as resolved.
|
||
|
|
||
| /************** | ||
| * PROTOTYPES * | ||
| **************/ | ||
| void noise(const char *msg); | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include "sighandlers.h" | ||
|
|
||
| extern void sighandle_sigint(int sig) { | ||
| (void) sig; | ||
| event = Event_sigint; | ||
| } | ||
|
logic-finder marked this conversation as resolved.
|
||
|
|
||
| extern void sighandle_sigquit(int sig) { | ||
| (void) sig; | ||
| event = Event_sigquit; | ||
| } | ||
|
logic-finder marked this conversation as resolved.
|
||
|
|
||
| extern void sighandle_sigterm(int sig) { | ||
| (void) sig; | ||
| event = Event_sigterm; | ||
| } | ||
|
logic-finder marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef SIGHANDLERS_H | ||
| #define SIGHANDLERS_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include "global.h" | ||
| #include "wrappers.h" | ||
|
|
||
| /************** | ||
| * PROTOTYPES * | ||
| **************/ | ||
| sighandler_t sighandle_sigint; | ||
| sighandler_t sighandle_sigquit; | ||
| sighandler_t sighandle_sigterm; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #include "utils.h" | ||
|
|
||
| extern void seed(void) { | ||
| srand(time(NULL)); | ||
| } | ||
|
|
||
| extern int rand_range(int min, int max) { | ||
| if (max <= 0) | ||
| VERR("max must be greater than 0, but given %d", max); | ||
| return min + rand() / (RAND_MAX / max + 1); | ||
|
logic-finder marked this conversation as resolved.
|
||
| } | ||
|
|
||
| extern int mblen_(char ch) { | ||
| unsigned char c; | ||
|
|
||
| c = (unsigned char) ch; | ||
|
|
||
| if (c < 0x80) return 1; /* 0xxxxxxx */ | ||
| if ((c & 0xE0) == 0xC0) return 2; /* 110xxxxx */ | ||
| if ((c & 0xF0) == 0xE0) return 3; /* 1110xxxx */ | ||
| if ((c & 0xF8) == 0xF0) return 4; /* 11110xxx */ | ||
|
|
||
| return 0; | ||
| } | ||
|
logic-finder marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #ifndef UTILS_H | ||
| #define UTILS_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include <time.h> | ||
| #include <stdlib.h> | ||
| # | ||
| #include "fatal.h" | ||
| #include "global.h" | ||
|
logic-finder marked this conversation as resolved.
|
||
|
|
||
| /************** | ||
| * PROTOTYPES * | ||
| **************/ | ||
| void seed(void); | ||
| int rand_range(int min, int max); | ||
| int mblen_(char ch); | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "wrappers.h" | ||
|
|
||
| /*********** | ||
| * stdio.h * | ||
| ***********/ | ||
| extern void safe_fputs(FILE *stream, const char *line) { | ||
| if (fputs(line, stream) == EOF) | ||
| ERR("fputs error"); | ||
| } | ||
|
|
||
| /************ | ||
| * stdarg.h * | ||
| ************/ | ||
| static const char *vfprintf_errmsg = "vfprintf error"; | ||
|
|
||
| extern void safe_fprintf(FILE *stream, const char *format, ...) { | ||
| va_list ap; | ||
| int ret; | ||
|
|
||
| va_start(ap, format); | ||
| ret = vfprintf(stream, format, ap); | ||
| if (ret < 0) ERR(vfprintf_errmsg); | ||
| va_end(ap); | ||
| } | ||
|
|
||
| extern void safe_vfprintf(FILE *stream, const char *format, va_list *ap) { | ||
| int ret; | ||
|
|
||
| ret = vfprintf(stream, format, *ap); | ||
| if (ret < 0) ERR(vfprintf_errmsg); | ||
| } | ||
|
|
||
| /************ | ||
| * signal.h * | ||
| ************/ | ||
| extern void safe_signal(int sig, sighandler_t handler) { | ||
| if (signal(sig, handler) == SIG_ERR) | ||
| ERR("signal error"); | ||
| } | ||
|
logic-finder marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef WRAPPERS_H | ||
| #define WRAPPERS_H | ||
|
|
||
| /************ | ||
| * INCLUDES * | ||
| ************/ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <stdarg.h> | ||
| # | ||
| #include "fatal.h" | ||
| #include "global.h" | ||
|
logic-finder marked this conversation as resolved.
|
||
|
|
||
| /************** | ||
| * PROTOTYPES * | ||
| **************/ | ||
| void safe_fputs(FILE *stream, const char *line); | ||
| void safe_fprintf(FILE *stream, const char *format, ...); | ||
| void safe_vfprintf(FILE *stream, const char *format, va_list *ap); | ||
| void safe_signal(int sig, sighandler_t handler); | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,25 @@ | ||
| #include <stdio.h> | ||
| #include "yandere.types.h" | ||
|
|
||
| int main(void) { | ||
| for (;;) | ||
| printf("이제 내가 싫어진거야? "); | ||
|
|
||
| seed(); | ||
| event = Event_default; | ||
| install_sighandlers(); | ||
| for (;;) dispatch(); | ||
|
logic-finder marked this conversation as resolved.
|
||
| return 0; | ||
| } | ||
| } | ||
|
|
||
| static void install_sighandlers(void) { | ||
| safe_signal(SIGINT , sighandle_sigint); | ||
| safe_signal(SIGQUIT, sighandle_sigquit); | ||
| safe_signal(SIGTERM, sighandle_sigterm); | ||
| } | ||
|
|
||
| static void dispatch(void) { | ||
| switch (event) { | ||
| case Event_default: evthandle_default(); break; | ||
| case Event_sigint : evthandle_sigint (); break; | ||
| case Event_sigquit: evthandle_sigquit(); break; | ||
| case Event_sigterm: evthandle_sigterm(); break; | ||
| default: ERR("control reaches default"); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.