Skip to content

Instantly share code, notes, and snippets.

Created February 11, 2018 07:24
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mjg59/ccbeec81dacd38eac5fd92e121faa5fc to your computer and use it in GitHub Desktop.
#include <signal.h>
#include <stdio.h>
#include <malloc.h>
#include <setjmp.h>
#include <stdbool.h>
static jmp_buf omg;
struct list {
char dummy[16384];
struct list *next;
static void handler(int sig, siginfo_t *si, void *unused)
longjmp(omg, 1);
bool list_cycle(struct list *list)
struct sigaction sa;
struct list *prev;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handler;
if (sigaction(SIGABRT, &sa, NULL) == -1) {
return -1;
if (setjmp(omg))
return true;
while (list->next) {
prev = list;
list = list->next;
return false;
int main (int argc, char **argv) {
struct list *test, *test2;
test = malloc(sizeof(struct list));
test2 = malloc(sizeof(struct list));
test->next = test2;
test2->next = test;
if (list_cycle(test) == true) {
} else {
printf("no loop\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment