Example #1
0
static void always_ok(void)
{
	var_a ++;
	var_a = VALUE_A;
	var_a = (enum ENUM_TYPE_A) VALUE_B;
	var_b = (enum ENUM_TYPE_B) i;
	i = (int) VALUE_A;
	anon_enum_var = VALUE_C;
	i = VALUE_C;
	i = anon_enum_var;
	i = 7;
	var_a = (enum ENUM_TYPE_A) 0;
	anon_enum_var = (__typeof__(anon_enum_var)) 0;
	anon_enum_var = (__typeof__(anon_enum_var)) VALUE_A;

	switch (var_a) {
		case VALUE_A:
		default:
			take_enum_of_type_a(var_a);
			take_enum_of_type_a(VALUE_A);
	}

	switch (anon_enum_var) {
		case VALUE_C:
		default:
			take_int(anon_enum_var);
	}

	switch (i) {
		case VALUE_C:
		default:
			take_int(VALUE_C);
	}
}
int foo(int n)
{
  int (*t)[n];
  i = 0;
  int j = 0;
  char b[1][n+3];			/* Variable length array.  */
  int d[3][n];				/* Variable length array.  */
  sizeof (b[i++ + sizeof(j++)]);	/* Outer sizeof is evaluated for vla, but not the inner one.  */
  if (i != 1 || j != 0)
    return 1;
  __typeof__(b[i++]) c1;		/* typeof is evauluated when given a vm */
  if (i != 2)
    return 1;
  __typeof__(t + (i++,0)) c2;		/* typeof is evauluated when given a vm */
  if (i != 3)
    return 1;
  __typeof__(i + (i++,0)) c3;		/* typeof is not evauluated when not given a vm */
  if (i != 3)
    return 1;
  sizeof (d[i++]);			/* sizeof is evaluated for vla.  */
  if (i != 4)
    return 1;
  __alignof__(__typeof__(t + (i++,0)));	/* typeof is not evauluated when given a vm inside alignof*/
  if (i != 4)
    return 1;
  sizeof(__typeof__(t + (i++,0)));	/* typeof is not evauluated when given a vm inside sizeof*/
  if (i != 4)
    return 1;
  return 0;
}
Example #3
0
__inline__ void netbench_printer_print_single(
	enum netbench_printer_type prtype,
	enum netbench_test_type tetype,
	struct linked_list *results,
	int srank,
	int drank
)
{
	__typeof__(results) ptr;
	struct netbench_result *resptr;

	ptr = results;
	resptr = ptr->value->u.res;
	while ((ptr)
		&& (
			(resptr->srank != srank) 
			|| (resptr->drank != drank)
			|| (resptr->type != tetype)
		)
	)
	{
		if (ptr->value)
			resptr = ptr->value->u.res;
		else
			resptr = 0;
		ptr = ptr->next;
	}

	if ((resptr) && (resptr->srank == srank) && (resptr->drank == drank)
		&& (resptr->type == tetype)
	)
		netbench_result_print(prtype,resptr);
	else
		fprintf(stdout,"N/A");
}
Example #4
0
struct linked_list *ll_alloc()
{
	struct linked_list *ret;
	ret = (__typeof__(ret)) malloc((size_t) sizeof(*ret));
	ret->head = NULL;
	return ret;
}
Example #5
0
static int ReadBlock (const char *key, void *block, int max_len, STREAM snap)
{
    char buffer [20];
    int len = 0;
    int rem = 0;

    if (READ_STREAM (buffer, 11, snap) != 11 ||
	strncmp (buffer, key, 4) != 0 ||
	(len = atoi (&buffer [4])) == 0)
	return (WRONG_FORMAT);

    if (len > max_len)
    {
	rem = len - max_len;
	len = max_len;
    }
    if (READ_STREAM (block, len, snap) != (__typeof__(READ_STREAM(block, len, snap)))len)
	return (WRONG_FORMAT);

    if (rem)
    {
	char *junk = new char [rem];
	READ_STREAM (junk, rem, snap);
	delete[] junk;
    }

    return (SUCCESS);
}
void ctor() {
	states = Allocator( sizeof(__typeof__(states[0])) * N * PADRATIO);
	for ( int i = 0; i < N; i += 1 ) {					// initialize shared data
		states[i*PADRATIO] = ATOMIC_VAR_INIT(UNLOCKED);
	} // for
	turn = ATOMIC_VAR_INIT(0);
} // ctor
Example #7
0
errno_t
utun_ctl_start_crypto_data_traffic (__unused kern_ctl_ref  kctlref,
				    __unused u_int32_t     unit, 
				    __unused void         *unitinfo,
				    __unused int           opt, 
				    void                  *data, 
				    size_t                 len)
{
	struct utun_pcb	*pcb = unitinfo;

	/*
	 * - verify the crypto context args passed from user-land.
	 *    - check the size of the argument buffer.
	 *    - check the direction (IN or OUT)
	 *    - check the type (IPSec or DTLS)
	 * - ensure that the crypto context *is* already valid (don't release invalid context).
	 *    - we have only one context per direction and type.
	 * - ensure that the crypto context has no crypto material.
	 * - any error should be equivalent to noop.
	 */
	if (len < UTUN_CRYPTO_ARGS_HDR_SIZE) {
		return EMSGSIZE;
	} else {
		utun_crypto_args_t *crypto_args = (__typeof__(crypto_args))data;

		if (crypto_args->ver == 0 || crypto_args->ver >= UTUN_CRYPTO_ARGS_VER_MAX) {
			printf("%s: ver check failed %d\n", __FUNCTION__, crypto_args->ver);
			return EINVAL;
		}
		if (crypto_args->type == 0 || crypto_args->type >= UTUN_CRYPTO_TYPE_MAX) {
			printf("%s: type check failed %d\n", __FUNCTION__, crypto_args->type);
			return EINVAL;
		}
		if (len < UTUN_CRYPTO_ARGS_TOTAL_SIZE(crypto_args)) {
			printf("%s: vlen check failed (%d,%d)\n", __FUNCTION__,
				   (int)len, (int)UTUN_CRYPTO_ARGS_TOTAL_SIZE(crypto_args));
			return EINVAL;
		}
		if (crypto_args->args_ulen != sizeof(crypto_args->u)) {
			printf("%s: compatibility mode\n", __FUNCTION__);
		}

		if ((pcb->utun_flags & UTUN_FLAGS_CRYPTO) == 0) {
			printf("%s: crypto is already disabled\n", __FUNCTION__);
			return EINVAL;
		}

		if (crypto_args->type == UTUN_CRYPTO_TYPE_IPSEC) {
			// nothing
		} else if (crypto_args->type == UTUN_CRYPTO_TYPE_DTLS) {
			utun_ctl_start_datatraffic_crypto_dtls(pcb);
		} else {
			// unsupported
			return EPROTONOSUPPORT;
		}
	}
	pcb->utun_flags &= ~UTUN_FLAGS_CRYPTO_STOP_DATA_TRAFFIC;
	return 0;
}
Example #8
0
void test1()
{
  int a;
  __typeof__(a) b;

  a = b = 10;
  printf("a = %d, b = %d\n", a, b);
}
Example #9
0
void
non_evaluated (void)
{
  s = sizeof (f + 1.0);             /* { dg-bogus "implicit" } */
  s = __alignof__ (f + 1.0);        /* { dg-bogus "implicit" } */
  d = (__typeof__(f + 1.0))f;       /* { dg-bogus "implicit" } */
  s = sizeof (i ? f : d);           /* { dg-bogus "implicit" } */
}
Example #10
0
static void *mdev_mmap(const struct region_device *rd, size_t offset,
			size_t size __unused)
{
	const struct mem_region_device *mdev;

	mdev = container_of(rd, __typeof__(*mdev), rdev);

	return &mdev->base[offset];
}
Example #11
0
/* If your code wants to avoid the wrapper above, call this version */
unsigned int real_sleep(unsigned int seconds) {
  static unsigned int (*real_fnc)() = NULL; /* Same type signature as sleep */
  static void *handle = NULL;

  if (! handle)
    handle = dlopen("libc.so.6", RTLD_NOW);
  if (! real_fnc)
    real_fnc = (__typeof__(real_fnc)) dlsym(handle, "sleep");
  return (*real_fnc)(seconds);
}
Example #12
0
asmlinkage int __ipipe_syscall_root(struct pt_regs *regs)
{
    struct ipipe_percpu_domain_data *p;
    void (*hook)(void);
    int ret;

    WARN_ON_ONCE(irqs_disabled_hw());

    /*
     * We need to run the IRQ tail hook each time we intercept a
     * syscall, because we know that important operations might be
     * pending there (e.g. Xenomai deferred rescheduling).
     */
    hook = (__typeof__(hook))__ipipe_irq_tail_hook;
    hook();

    /*
     * This routine either returns:
     * 0 -- if the syscall is to be passed to Linux;
     * >0 -- if the syscall should not be passed to Linux, and no
     * tail work should be performed;
     * <0 -- if the syscall should not be passed to Linux but the
     * tail work has to be performed (for handling signals etc).
     */

    if (!__ipipe_syscall_watched_p(current, regs->orig_p0) ||
            !__ipipe_event_monitored_p(IPIPE_EVENT_SYSCALL))
        return 0;

    ret = __ipipe_dispatch_event(IPIPE_EVENT_SYSCALL, regs);

    hard_local_irq_disable();

    /*
     * This is the end of the syscall path, so we may
     * safely assume a valid Linux task stack here.
     */
    if (current->ipipe_flags & PF_EVTRET) {
        current->ipipe_flags &= ~PF_EVTRET;
        __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
    }

    if (!__ipipe_root_domain_p)
        ret = -1;
    else {
        p = ipipe_root_cpudom_ptr();
        if (__ipipe_ipending_p(p))
            __ipipe_sync_pipeline();
    }

    hard_local_irq_enable();

    return -ret;
}
Example #13
0
void
_cgo_5b040d13e328_Cfunc_getint(void *v)
{
	struct {
		int r;
	} __attribute__((__packed__, __gcc_struct__)) *a = v;
	char *stktop = _cgo_topofstack();
	__typeof__(a->r) r = getint();
	a = (void*)((char*)a + (_cgo_topofstack() - stktop));
	a->r = r;
}
Example #14
0
static int
get_address_family (int fd)
{
  struct sockaddr_storage sa;
  socklen_t sa_len = sizeof (sa);
  if (__getsockname (fd, (struct sockaddr *) &sa, &sa_len) < 0)
    return -1;
  /* Check that the socket family number is preserved despite in-band
     signaling.  */
  _Static_assert (sizeof (sa.ss_family) < sizeof (int), "address family size");
  _Static_assert (0 < (__typeof__ (sa.ss_family)) -1,
                  "address family unsigned");
  return sa.ss_family;
}
Example #15
0
static gboolean timeout_sigkill(gpointer data)
{
	char *mount_dir = (char*)data;
	lsof_result_t ls;

	get_fsusers(&ls, mount_dir);
	
	for (__typeof__(ls.fsusers.end()) i = ls.fsusers.begin(); i != ls.fsusers.end(); i++) {
		kill((*i).pid, SIGKILL);
	}
	
	g_timeout_add (500, timeout_unmount, data);
	printf("Hello timeout!\n");

	return FALSE;
}
Example #16
0
bool
ll_add_head( struct linked_list *list, struct linked_list_element **element )
{
	if( *element == NULL )
	{
		*element = (__typeof__(*element))
			malloc((size_t) sizeof(**element));
		if( *element == NULL )
			return false;
	}

	(*element)->next = list->head;
	(*element)->addr = element;
	list->head = *element;

	return true;
}
Example #17
0
// Test the conditional operator with vector types.
void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e,
                 longlong16_e ll16e) {
  // Conditional operators with the same type.
  __typeof__(Cond? c16 : c16) *c16p1 = &c16;
  __typeof__(Cond? ll16 : ll16) *ll16p1 = &ll16;
  __typeof__(Cond? c16e : c16e) *c16ep1 = &c16e;
  __typeof__(Cond? ll16e : ll16e) *ll16ep1 = &ll16e;

  // Conditional operators with similar types.
  __typeof__(Cond? c16 : c16e) *c16ep2 = &c16e;
  __typeof__(Cond? c16e : c16) *c16ep3 = &c16e;
  __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e;
  __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e;

  // Conditional operators with compatible types under -flax-vector-conversions (default)
  (void)(Cond? c16 : ll16);
  (void)(Cond? ll16e : c16e);
  (void)(Cond? ll16e : c16);
}
Example #18
0
foo (int n)
{
  struct S { int a[n]; };

  struct S __attribute__((noreturn))
  fn (void)
  {
    __builtin_abort ();
  }

  auto struct S __attribute__((noreturn))
  fn2 (void)
  {
    __builtin_abort ();
  }

  struct S x;
  __typeof__ (fn ()) *p = &x;
  switch (n)
    {
    case 1:
      fn ();
      break;
    case 2:
      fn2 ();
      break;
    case 3:
      x = fn ();
      if (x.a[0] != 42)
	__builtin_abort ();
      break;
    case 4:
      if (fn ().a[0] != 42)
	__builtin_abort ();
      break;
    case 5:
      if (p->a[0] != 42)
	__builtin_abort ();
      break;
    case 6:
      if (fn2 ().a[0] != 42)
	__builtin_abort ();
      break;
    }
}
CGO_NO_SANITIZE_THREAD
void
_cgo_506f45f9fa85_Cfunc_sum(void *v)
{
	struct {
		int p0;
		int p1;
		int r;
		char __pad12[4];
	} __attribute__((__packed__)) *a = v;
	char *stktop = _cgo_topofstack();
	__typeof__(a->r) r;
	_cgo_tsan_acquire();
	r = sum(a->p0, a->p1);
	_cgo_tsan_release();
	a = (void*)((char*)a + (_cgo_topofstack() - stktop));
	a->r = r;
}
Example #20
0
static void
monitorApple80211Callback (Apple80211Err  err,
						   Apple80211Ref  ref,
						   UInt32         event,
						   void          *eventData,
						   UInt32         eventDataLen,
						   void          *context)
{
	struct service *serv = (__typeof__(serv))context;

	if (!serv) {
		return;
	}

	if (event ==  APPLE80211_M_SSID_CHANGED) {
		SCLog(TRUE, LOG_INFO, CFSTR("%s: VPN got wifi event %d"), __FUNCTION__, event);
		disconnectIfVPNLocationChanged(serv);
	}
}
Example #21
0
static void
mr_value_id (mr_value_t * value)
{
  if (MR_VT_ID != value->value_type)
    return;

  value->value_type = MR_VT_INT;
  if (NULL == value->vt_string)
    value->vt_int = 0;
  else
    {
      mr_fd_t * fdp = mr_get_enum_by_name (value->vt_string);
      __typeof__ (value->vt_int) vt_int = 0;
      if (NULL == fdp)
	MR_MESSAGE (MR_LL_WARN, MR_MESSAGE_UNKNOWN_ENUM, value->vt_string);
      else
	vt_int = fdp->param.enum_value;
      MR_FREE (value->vt_string);
      value->vt_int = vt_int;
    }
}
Example #22
0
void
foo (int n)
{
  struct S { int a[n]; };

  struct S
  fn (void)
  {
    struct S s;
    s.a[0] = 42;
    return s;
  }

  auto struct S
  fn2 (void)
  {
    return fn ();
  }

  struct S x;
  fn ();
  fn2 ();
  x = fn ();

  if (x.a[0] != 42)
    __builtin_abort ();

  if (fn ().a[0] != 42)
    __builtin_abort ();

  __typeof__ (fn ()) *p = &x;
  if (p->a[0] != 42)
    __builtin_abort ();

  if (fn2 ().a[0] != 42)
    __builtin_abort ();
}
Example #23
0
static void ExceptionThread(mach_port_t port)
{
	Common::SetCurrentThreadName("Mach exception thread");
	#pragma pack(4)
	struct
	{
		mach_msg_header_t Head;
		NDR_record_t NDR;
		exception_type_t exception;
		mach_msg_type_number_t codeCnt;
		int64_t code[2];
		int flavor;
		mach_msg_type_number_t old_stateCnt;
		natural_t old_state[x86_THREAD_STATE64_COUNT];
		mach_msg_trailer_t trailer;
	} msg_in;

	struct
	{
		mach_msg_header_t Head;
		NDR_record_t NDR;
		kern_return_t RetCode;
		int flavor;
		mach_msg_type_number_t new_stateCnt;
		natural_t new_state[x86_THREAD_STATE64_COUNT];
	} msg_out;
	#pragma pack()
	memset(&msg_in, 0xee, sizeof(msg_in));
	memset(&msg_out, 0xee, sizeof(msg_out));
	mach_msg_header_t *send_msg = nullptr;
	mach_msg_size_t send_size = 0;
	mach_msg_option_t option = MACH_RCV_MSG;
	while (true)
	{
		// If this isn't the first run, send the reply message.  Then, receive
		// a message: either a mach_exception_raise_state RPC due to
		// thread_set_exception_ports, or MACH_NOTIFY_NO_SENDERS due to
		// mach_port_request_notification.
		CheckKR("mach_msg_overwrite", mach_msg_overwrite(send_msg, option, send_size, sizeof(msg_in), port, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL, &msg_in.Head, 0));

		if (msg_in.Head.msgh_id == MACH_NOTIFY_NO_SENDERS)
		{
			// the other thread exited
			mach_port_destroy(mach_task_self(), port);
			return;
		}

		if (msg_in.Head.msgh_id != 2406)
		{
			PanicAlert("unknown message received");
			return;
		}

		if (msg_in.flavor != x86_THREAD_STATE64)
		{
			PanicAlert("unknown flavor %d (expected %d)", msg_in.flavor, x86_THREAD_STATE64);
			return;
		}

		x86_thread_state64_t *state = (x86_thread_state64_t *) msg_in.old_state;

		bool ok = JitInterface::HandleFault((uintptr_t) msg_in.code[1], state);

		// Set up the reply.
		msg_out.Head.msgh_bits = MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(msg_in.Head.msgh_bits), 0);
		msg_out.Head.msgh_remote_port = msg_in.Head.msgh_remote_port;
		msg_out.Head.msgh_local_port = MACH_PORT_NULL;
		msg_out.Head.msgh_id = msg_in.Head.msgh_id + 100;
		msg_out.NDR = msg_in.NDR;
		if (ok)
		{
			msg_out.RetCode = KERN_SUCCESS;
			msg_out.flavor = x86_THREAD_STATE64;
			msg_out.new_stateCnt = x86_THREAD_STATE64_COUNT;
			memcpy(msg_out.new_state, msg_in.old_state, x86_THREAD_STATE64_COUNT * sizeof(natural_t));
		}
		else
		{
			// Pass the exception to the next handler (debugger or crash).
			msg_out.RetCode = KERN_FAILURE;
			msg_out.flavor = 0;
			msg_out.new_stateCnt = 0;
		}
		msg_out.Head.msgh_size = offsetof(__typeof__(msg_out), new_state) + msg_out.new_stateCnt * sizeof(natural_t);

		send_msg = &msg_out.Head;
		send_size = msg_out.Head.msgh_size;
		option |= MACH_SEND_MSG;
	}
}
Example #24
0
// RUN: %clang_cc1 -fsyntax-only -verify %s

void f();

// Test typeof(expr) canonicalization
template<typename T>
void f0(T x, __typeof__(f(x)) y) { } // expected-note{{previous}}

template<typename T>
void f0(T x, __typeof__((f)(x)) y) { }

template<typename U>
void f0(U u, __typeof__(f(u))) { } // expected-error{{redefinition}}

// Test insane typeof(expr) overload set canonicalization
void f(int);
void f(double);

template<typename T, T N>
void f0a(T x, __typeof__(f(N)) y) { } // expected-note{{previous}}

void f(int);

template<typename T, T N>
void f0a(T x, __typeof__(f(N)) y) { } // expected-error{{redefinition}}

void f(float);

// Test dependently-sized array canonicalization
template<typename T, int N, int M>
void f1(T (&array)[N + M]) { } // expected-note{{previous}}
Example #25
0
int
main(int argc, char **argv)
{
	struct maze *m;
	struct square s;
	struct element *e;
	struct maze_markov_decision_process *mdp;
	int tmp;

	if (argc < 2)
	{
		printf( "usage: %s <algorithm> [Q-learling limit]\n"
			"\t[0] Value Iteration\n"
			"\t[1] Policy Iteration\n"
			"\t[2] Q-learning\n",
			argv[0]
		);
		exit(EXIT_SUCCESS);
	}
	
	m = maze_create(5,3);
	e = (__typeof__(e)) malloc(sizeof(struct element));

	s.element = e;
	e->name = 'R';
	e->type = MAZE_ELEM_TYPE_INIT;

	maze_add(m,&s,0,0);
	s.element = 0;
	maze_add(m,&s,0,1);
	e->name = 'G';
	e->reward = 1;
	e->type = MAZE_ELEM_TYPE_GOAL;
	s.element = e;
	maze_add(m,&s,0,2);
	s.element = 0;
	maze_add(m,&s,1,2);
	e->name = 'F';
	e->reward = 10;
	e->type = MAZE_ELEM_TYPE_GOAL;
	s.element = e;
	maze_add(m,&s,2,0);
	s.element = 0;
	maze_add(m,&s,2,1);
	maze_add(m,&s,2,2);
	maze_add(m,&s,3,2);
	maze_add(m,&s,4,0);
	maze_add(m,&s,4,1);
	maze_add(m,&s,4,2);


	maze_display(m);
	printf("\n");
	/*
	MAZE_ELEMENT_MOVE_UP(m,e);
	MAZE_ELEMENT_MOVE_UP(m,e);
	MAZE_ELEMENT_MOVE_RIGHT(m,e);
	MAZE_ELEMENT_MOVE_LEFT(m,e);
	MAZE_ELEMENT_MOVE_LEFT(m,e);
	MAZE_ELEMENT_MOVE_LEFT(m,e);
	maze_display(m);
	*/

	mdp = maze_markov_decision_process_create(m);

	maze_markov_decision_process_display(mdp);

	if ((tmp = atoi(argv[1])) == 0)
		maze_solver_vi_perform(mdp);
	else if (tmp == 1)
		maze_solver_pi_perform(mdp);
	else
	{
		maze_solver_qlearning_perform(
			mdp,
			(argv[2] 
				? atoi(argv[2])
				: MAZE_SOLVER_QLEARNING_DEFAULT_ITER
			)
		);
	}

	free(e);
	maze_delete(m);
	maze_markov_decision_process_destroy(mdp);

	return 0;
}
Example #26
0
/* args:
 *      ctx	Context info, used when recalling a message to which
 *              we reply.
 *	hdr	envelope/attachment info for recalled message
 *	cur	if message was a reply, `cur' is set to the message which
 *		`hdr' is in reply to
 *	fcc	fcc for the recalled message
 *	fcclen	max length of fcc
 *
 * return vals:
 *	-1		error/no messages
 *	0		normal exit
 *	SENDREPLY	recalled message is a reply
 */
int mutt_get_postponed(CONTEXT *ctx,
                       HEADER  *hdr,
                       HEADER  **cur,
                       char    *fcc,
                       size_t  fcclen)
{
    HEADER *h;
    int code = SENDPOSTPONED;
    LIST *tmp;
    LIST *last = NULL;
    LIST *next;
    const char *p;
    int opt_delete;

    if (!Postponed)
        return -1;

    if ((PostContext = mx_open_mailbox(Postponed, M_NOSORT, NULL)) == NULL) {
        PostCount = 0;
        mutt_error _("No postponed messages.");
        return -1;
    }

    if (!PostContext->msgcount) {
        PostCount = 0;
        mx_close_mailbox(PostContext, NULL);
        safe_free(&PostContext);
        mutt_error _("No postponed messages.");
        return -1;
    }

    if (PostContext->msgcount == 1) {
        /* only one message, so just use that one. */
        h = PostContext->hdrs[0];
    } else if ((h = select_msg()) == NULL) {
        mx_close_mailbox(PostContext, NULL);
        safe_free(&PostContext);
        return -1;
    }

    if (mutt_prepare_template(NULL, PostContext, hdr, h, 0) < 0) {
        mx_fastclose_mailbox(PostContext);
        safe_free(&PostContext);
        return -1;
    }

    /* finished with this message, so delete it. */
    mutt_set_flag(PostContext, h, M_DELETE, 1);

    /* update the count for the status display */
    PostCount = PostContext->msgcount - PostContext->deleted;

    /* avoid the "purge deleted messages" prompt */
    opt_delete = quadoption(OPT_DELETE);
    set_quadoption(OPT_DELETE, M_YES);
    mx_close_mailbox(PostContext, NULL);
    set_quadoption(OPT_DELETE, opt_delete);

    safe_free(&PostContext);

    for (tmp = hdr->env->userhdrs; tmp;) {
        if (ascii_strncasecmp("X-Mutt-References:", tmp->data, 18) == 0) {
            if (ctx) {
                /* if a mailbox is currently open, look to see if the orignal
                   message
                   the user attempted to reply to is in this mailbox */
                p = skip_email_wsp(tmp->data + 18);

                if (!ctx->id_hash)
                    ctx->id_hash = mutt_make_id_hash(ctx);
                *cur = (__typeof__(*cur)) hash_find(ctx->id_hash, p);
            }

            /* Remove the X-Mutt-References: header field. */
            next = tmp->next;

            if (last)
                last->next = tmp->next;
            else
                hdr->env->userhdrs = tmp->next;
            tmp->next = NULL;
            mutt_free_list(&tmp);
            tmp = next;

            if (*cur)
                code |= SENDREPLY;
        } else if (ascii_strncasecmp("X-Mutt-Fcc:", tmp->data, 11) == 0) {
            p = skip_email_wsp(tmp->data + 11);
            strfcpy(fcc, p, fcclen);
            mutt_pretty_mailbox(fcc, fcclen);

            /* remove the X-Mutt-Fcc: header field */
            next = tmp->next;

            if (last)
                last->next = tmp->next;
            else
                hdr->env->userhdrs = tmp->next;
            tmp->next = NULL;
            mutt_free_list(&tmp);
            tmp = next;

            /* note that x-mutt-fcc was present.  we do this because we want to
               add a
             * default fcc if the header was missing, but preserve the request
             *of the
             * user to not make a copy if the header field is present, but
             *empty.
             * see http://dev.mutt.org/trac/ticket/3653
             */
            code |= SENDPOSTPONEDFCC;
        } else if ((WithCrypto & APPLICATION_PGP)
                   && ((mutt_strncmp("Pgp:", tmp->data, 4) == 0) /* this is
                                                                    generated
                                                                  * by old mutt
                                                                  *versions
                                                                  */
                       || (mutt_strncmp("X-Mutt-PGP:", tmp->data, 11) == 0))) {
            hdr->security = mutt_parse_crypt_hdr(strchr(tmp->data, ':') + 1, 1,
                                                 APPLICATION_PGP);
            hdr->security |= APPLICATION_PGP;

            /* remove the pgp field */
            next = tmp->next;

            if (last)
                last->next = tmp->next;
            else
                hdr->env->userhdrs = tmp->next;
            tmp->next = NULL;
            mutt_free_list(&tmp);
            tmp = next;
        } else if ((WithCrypto & APPLICATION_SMIME)
                   && (mutt_strncmp("X-Mutt-SMIME:", tmp->data, 13) == 0)) {
            hdr->security = mutt_parse_crypt_hdr(strchr(tmp->data, ':') + 1, 1,
                                                 APPLICATION_SMIME);
            hdr->security |= APPLICATION_SMIME;

            /* remove the smime field */
            next = tmp->next;

            if (last)
                last->next = tmp->next;
            else
                hdr->env->userhdrs = tmp->next;
            tmp->next = NULL;
            mutt_free_list(&tmp);
            tmp = next;
        }

#ifdef MIXMASTER
        else if (mutt_strncmp("X-Mutt-Mix:", tmp->data, 11) == 0) {
            char *t;
            mutt_free_list(&hdr->chain);

            t = strtok(tmp->data + 11, " \t\n");

            while (t) {
                hdr->chain = mutt_add_list(hdr->chain, t);
                t = strtok(NULL, " \t\n");
            }

            next = tmp->next;

            if (last)
                last->next = tmp->next;
            else
                hdr->env->userhdrs = tmp->next;
            tmp->next = NULL;
            mutt_free_list(&tmp);
            tmp = next;
        }
#endif /* ifdef MIXMASTER */

        else {
            last = tmp;
            tmp = tmp->next;
        }
    }

    if (globals.has_option(OPTCRYPTOPPORTUNISTICENCRYPT))
        crypt_opportunistic_encrypt(hdr);

    return code;
}
Example #27
0
File: new.c Project: danpoe/cbmc
/* FUNCTION: __new */

__CPROVER_bool __VERIFIER_nondet___CPROVER_bool();

inline void *__new(__typeof__(sizeof(int)) malloc_size)
{
  // The constructor call is done by the front-end.
  // This just does memory allocation.
  __CPROVER_HIDE:;
  void *res;
  res=__CPROVER_malloc(malloc_size);

  // ensure it's not recorded as deallocated
  __CPROVER_deallocated=(res==__CPROVER_deallocated)?0:__CPROVER_deallocated;

  // non-derministically record the object size for bounds checking
  __CPROVER_bool record_malloc=__VERIFIER_nondet___CPROVER_bool();
  __CPROVER_malloc_object=record_malloc?res:__CPROVER_malloc_object;
  __CPROVER_malloc_size=record_malloc?malloc_size:__CPROVER_malloc_size;
  __CPROVER_malloc_is_new_array=record_malloc?0:__CPROVER_malloc_is_new_array;

  // detect memory leaks
  __CPROVER_bool record_may_leak=__VERIFIER_nondet___CPROVER_bool();
  __CPROVER_memory_leak=record_may_leak?res:__CPROVER_memory_leak;

  return res;
}

/* FUNCTION: __new_array */

__CPROVER_bool __VERIFIER_nondet___CPROVER_bool();
  class Parser {
    void setFilename(const string& f)  {
      inputState->filename = f;
#ifndef SUPPRESSED
// expected-warning@-2 {{Called C++ object pointer is null}}
#endif
    }
  protected:
    RefCount<ParserInputState> inputState;
  };
}


// This is the standard placement new.
inline void* operator new(__typeof__(sizeof(int)), void* __p) throw()
{
  return __p;
}

extern bool coin();

namespace References {
  class Map {
    int *&getNewBox();
    int *firstBox;

  public:
    int *&getValue(int key) {
      if (coin()) {
        return firstBox;
Example #29
0
/* returns: 1=0 on success, < 0 on error, 1 if no free/used partition */
int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew)
{
	int rc = 0, inchar = 0;
	char range[BUFSIZ], *ptr = range;
	size_t i, len = sizeof(range), begin = 0, run = 0;
	struct fdisk_ask *ask = NULL;
	__typeof__(ask->data.num) *num;

	assert(cxt);
	assert(cxt->label);
	assert(partnum);

	if (cxt->label && cxt->label->flags & FDISK_LABEL_FL_INCHARS_PARTNO)
		inchar = 1;

	DBG(ASK, dbgprint("%s: asking for %s partition number "
			  "(max: %zd, inchar: %s)",
			cxt->label->name,
			wantnew ? "new" : "used",
			cxt->label->nparts_max,
			inchar ? "yes" : "not"));

	ask = fdisk_new_ask();
	if (!ask)
		return -ENOMEM;

	fdisk_ask_set_type(ask, FDISK_ASKTYPE_NUMBER);
	num = &ask->data.num;

	ask->data.num.inchars = inchar ? 1 : 0;

	for (i = 0; i < cxt->label->nparts_max; i++) {
		int status = 0;

		rc = fdisk_partition_get_status(cxt, i, &status);
		if (rc)
			break;
		if (wantnew && !(status & FDISK_PARTSTAT_USED)) {
			ptr = mk_string_list(ptr, &len, &begin, &run, i, inchar);
			if (!ptr) {
				rc = -EINVAL;
				break;
			}
			if (!num->low)
				num->dfl = num->low = i + 1;
			num->hig = i + 1;
		} else if (!wantnew && (status & FDISK_PARTSTAT_USED)) {
			ptr = mk_string_list(ptr, &len, &begin, &run, i, inchar);
			if (!num->low)
				num->low = i + 1;
			num->dfl = num->hig = i + 1;
		}
	}

	DBG(ASK, dbgprint("ask limits: low: %zd, high: %zd, default: %zd",
				num->low, num->hig, num->dfl));

	if (!rc && !wantnew && num->low == num->hig) {
		if (num->low > 0) {
			/* only one existing partiton, don't ask, return the number */
			fdisk_ask_number_set_result(ask, num->low);
			fdisk_info(cxt, _("Selected partition %d"), num->low);

		} else if (num->low == 0) {
			fdisk_warnx(cxt, _("No partition is defined yet!"));
			rc = 1;
		}
		goto dont_ask;
	}
	if (!rc && wantnew && num->low == num->hig) {
		if (num->low > 0) {
			/* only one free partition, don't ask, return the number */
			fdisk_ask_number_set_result(ask, num->low);
			fdisk_info(cxt, _("Selected partition %d"), num->low);
		}
		if (num->low == 0) {
			fdisk_warnx(cxt, _("No free partition available!"));
			rc = 1;
		}
		goto dont_ask;
	}
	if (!rc) {
		mk_string_list(ptr, &len, &begin, &run, -1, inchar);	/* terminate the list */
		rc = fdisk_ask_number_set_range(ask, range);
	}
	if (!rc)
		rc = fdisk_ask_set_query(ask, _("Partition number"));
	if (!rc)
		rc = fdisk_do_ask(cxt, ask);

dont_ask:
	if (!rc) {
		*partnum = fdisk_ask_number_get_result(ask);
		if (*partnum)
			*partnum -= 1;
	}
	DBG(ASK, dbgprint("result: %zd [rc=%d]\n", fdisk_ask_number_get_result(ask), rc));
	fdisk_free_ask(ask);
	return rc;
}
Example #30
0
static int dvd_read_sector(dvd_priv_t *d, unsigned char *data)
{
  int len;

  if(d->packs_left==0) {
    /**
     * If we're not at the end of this cell, we can determine the next
     * VOBU to display using the VOBU_SRI information section of the
     * DSI.  Using this value correctly follows the current angle,
     * avoiding the doubled scenes in The Matrix, and makes our life
     * really happy.
     *
     * Otherwise, we set our next address past the end of this cell to
     * force the code above to go to the next cell in the program.
     */
    if(d->dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL) {
       d->cur_pack= d->dsi_pack.dsi_gi.nv_pck_lbn + ( d->dsi_pack.vobu_sri.next_vobu & 0x7fffffff );
       mp_msg(MSGT_DVD,MSGL_DBG2, "Navi  new pos=0x%X  \n",d->cur_pack);
    } else {
      // end of cell! find next cell!
      mp_msg(MSGT_DVD,MSGL_V, "--- END OF CELL !!! ---\n");
      d->cur_pack=d->cell_last_pack+1;
    }
  }

read_next:
  if(d->cur_pack>d->cell_last_pack) {
    // end of cell!
    int next=dvd_next_cell(d);
    if(next>=0) {
      d->cur_cell=next;
      // if( d->cur_pgc->cell_playback[d->cur_cell].block_type
      // == BLOCK_TYPE_ANGLE_BLOCK ) d->cur_cell+=dvd_angle;
      d->cur_pack = d->cur_pgc->cell_playback[ d->cur_cell ].first_sector;
      d->cell_last_pack=d->cur_pgc->cell_playback[ d->cur_cell ].last_sector;
      mp_msg(MSGT_DVD,MSGL_V, "DVD next cell: %d  pack: 0x%X-0x%X  \n",d->cur_cell,d->cur_pack,d->cell_last_pack);
    } else
        return -1; // EOF
  }

  len = DVDReadBlocks(d->title, d->cur_pack, 1, data);
  // only == 0 should indicate an error, but some dvdread version are buggy when used with dvdcss
  if(len <= 0) return -1; //error

  if(data[38]==0 && data[39]==0 && data[40]==1 && data[41]==0xBF &&
    data[1024]==0 && data[1025]==0 && data[1026]==1 && data[1027]==0xBF) {
       // found a Navi packet!!!
#if DVDREAD_VERSION >= LIBDVDREAD_VERSION(0,9,0)
    navRead_DSI(&d->dsi_pack, &(data[ DSI_START_BYTE ]));
#else
    navRead_DSI(&d->dsi_pack, &(data[ DSI_START_BYTE ]), sizeof(dsi_t));
#endif
    if(d->cur_pack != d->dsi_pack.dsi_gi.nv_pck_lbn ) {
      mp_msg(MSGT_DVD,MSGL_V, "Invalid NAVI packet! lba=0x%X  navi=0x%X  \n",
        d->cur_pack,d->dsi_pack.dsi_gi.nv_pck_lbn);
    } else {
      // process!
      d->packs_left = d->dsi_pack.dsi_gi.vobu_ea;
      mp_msg(MSGT_DVD,MSGL_DBG2, "Found NAVI packet! lba=0x%X  len=%d  \n",d->cur_pack,d->packs_left);
      //navPrint_DSI(&d->dsi_pack);
      mp_msg(MSGT_DVD,MSGL_DBG3,"\r### CELL %d: Navi: %d/%d  IFO: %d/%d   \n",d->cur_cell,
        d->dsi_pack.dsi_gi.vobu_c_idn,d->dsi_pack.dsi_gi.vobu_vob_idn,
        d->cur_pgc->cell_position[d->cur_cell].cell_nr,
        d->cur_pgc->cell_position[d->cur_cell].vob_id_nr);

      if(d->angle_seek) {
        int i,skip=0;
#if defined(__GNUC__) && ( defined(__sparc__) || defined(hpux) )
        // workaround for a bug in the sparc/hpux version of gcc 2.95.X ... 3.2,
        // it generates incorrect code for unaligned access to a packed
        // structure member, resulting in an mplayer crash with a SIGBUS
        // signal.
        //
        // See also gcc problem report PR c/7847:
        // http://gcc.gnu.org/cgi-bin/gnatsweb.pl?database=gcc&cmd=view+audit-trail&pr=7847
        for(i=0;i<9;i++) {	// check if all values zero:
          __typeof__(d->dsi_pack.sml_agli.data[i].address) tmp_addr;
          memcpy(&tmp_addr,&d->dsi_pack.sml_agli.data[i].address,sizeof(tmp_addr));
          if((skip=tmp_addr)!=0) break;
        }
#else
        for(i=0;i<9;i++)	// check if all values zero:
          if((skip=d->dsi_pack.sml_agli.data[i].address)!=0) break;
#endif
        if(skip && skip!=0x7fffffff) {
          // sml_agli table has valid data (at least one non-zero):
         d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+
         d->dsi_pack.sml_agli.data[dvd_angle].address;
         d->angle_seek=0;
         d->cur_pack--;
         mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced using sml_agli map!  new_lba=0x%X  \n",d->cur_pack);
        } else {
          // check if we're in the right cell, jump otherwise:
          if( (d->dsi_pack.dsi_gi.vobu_c_idn==d->cur_pgc->cell_position[d->cur_cell].cell_nr) &&
            (d->dsi_pack.dsi_gi.vobu_vob_idn==d->cur_pgc->cell_position[d->cur_cell].vob_id_nr) ){
            d->angle_seek=0;
            mp_msg(MSGT_DVD,MSGL_V, "Angle-seek synced by cell/vob IDN search!  \n");
          } else {
            // wrong angle, skip this vobu:
            d->cur_pack=d->dsi_pack.dsi_gi.nv_pck_lbn+
            d->dsi_pack.dsi_gi.vobu_ea;
            d->angle_seek=2; // DEBUG
          }
        }
      }
    }
    ++d->cur_pack;
    goto read_next;
  }

  ++d->cur_pack;
  if(d->packs_left>=0) --d->packs_left;

  if(d->angle_seek) {
    if(d->angle_seek==2) mp_msg(MSGT_DVD,MSGL_V, "!!! warning! reading packet while angle_seek !!!\n");
    goto read_next; // searching for Navi packet
  }

  return d->cur_pack-1;
}