コード例 #1
0
ファイル: main.cpp プロジェクト: AsherBond/MondocosmOS
/* ---------------------------------------------------------------------- */
void check_args() {

  /* check if filled elevation grid name is  valid */
  if (G_legal_filename (opt->filled_grid) < 0) {
    G_fatal_error(_("<%s> is an illegal file name"), opt->filled_grid);
  }
  /* check if output grid names are valid */
  if (G_legal_filename (opt->dir_grid) < 0) {
    G_fatal_error(_("<%s> is an illegal file name"), opt->dir_grid);
  }
  if (G_legal_filename (opt->filled_grid) < 0) {
    G_fatal_error(_("<%s> is an illegal file name"), opt->filled_grid);
  }
  if (G_legal_filename (opt->flowaccu_grid) < 0) {
    G_fatal_error(_("<%s> is an illegal file name"), opt->flowaccu_grid);
  }
  if (G_legal_filename (opt->watershed_grid) < 0) {
    G_fatal_error(_("<%s> is an illegal file name"), opt->watershed_grid);
  }
#ifdef OUTPU_TCI
  if (G_legal_filename (opt->tci_grid) < 0) {
  G_fatal_error(_("<%s> is an illegal file name"), opt->tci_grid);
  }
#endif
  
  /* check compatibility with region */
  check_header(opt->elev_grid);

  /* what else ? */  


}
コード例 #2
0
int
copen(const char *fname, int mode)
{
	int fd;
	struct sd *s = 0;

	if ( ((fd = open(fname, mode)) == -1) || (mode != O_RDONLY) )
		/* compression only for read */
		return(fd);

	ss[fd] = s = malloc(sizeof(struct sd));
	if (s == 0)
		goto errout;
	memset(s, 0, sizeof(struct sd));

	if (inflateInit2(&(s->stream), -15) != Z_OK)
		goto errout;

	s->stream.next_in  = s->inbuf = (unsigned char*)malloc(Z_BUFSIZE);
	if (s->inbuf == 0) {
		inflateEnd(&(s->stream));
		goto errout;
	}

	s->fd = fd;
	check_header(s); /* skip the .gz header */
	return(fd);

errout:
	if (s != 0)
		free(s);
	close(fd);
	return (-1);
}
コード例 #3
0
ファイル: mailinfo.c プロジェクト: 9b/git
static void flush_inbody_header_accum(struct mailinfo *mi)
{
	if (!mi->inbody_header_accum.len)
		return;
	assert(check_header(mi, &mi->inbody_header_accum, mi->s_hdr_data, 0));
	strbuf_reset(&mi->inbody_header_accum);
}
コード例 #4
0
ファイル: udp.c プロジェクト: roccof/groink
static int l_dissect_udp(lua_State *L)
{
  header_t *header = NULL;
  udp_t *udp = NULL;
  
  header = check_header(L, 1);
  udp = (udp_t *)header->data;

  lua_newtable(L);

  lua_pushstring(L, "src_port");
  lua_pushnumber(L, ntohs(udp->src_port));
  lua_settable(L, -3);

  lua_pushstring(L, "dst_port");
  lua_pushnumber(L, ntohs(udp->dest_port));
  lua_settable(L, -3);

  lua_pushstring(L, "payload_len");
  lua_pushnumber(L, ntohs(udp->len));
  lua_settable(L, -3);

  lua_pushstring(L, "cksum");
  lua_pushnumber(L, ntohs(udp->checksum));
  lua_settable(L, -3);

  se_setro(L);

  return 1;
}
コード例 #5
0
void dir_test()
{
    ar::tar::header head;
    head.format = ar::tar::pax;
    head.type_flag = ar::tar::type_flag::directory;
    head.path = "dir";
    head.modified_time = fs_ex::timestamp(std::time(0), 123456789);
    head.access_time = fs_ex::timestamp(1, 123456789);
    head.change_time = fs_ex::timestamp(12345, 0);
    head.file_size = 0;
    head.permissions = 0123;
    head.comment = "test comment";

    io_ex::tmp_file archive;
    ar::basic_tar_file_sink<
        io_ex::dont_close_device<io_ex::tmp_file>
    > sink(io_ex::dont_close(archive));

    sink.create_entry(head);
    sink.close();
    sink.close_archive();

    io::seek(archive, 0, BOOST_IOS::beg);

    ar::basic_tar_file_source<io_ex::tmp_file> src(archive);

    BOOST_CHECK(src.next_entry());

    check_header(head, src.header());

    BOOST_CHECK(!src.next_entry());
}
コード例 #6
0
ファイル: format_au.c プロジェクト: wildzero-cw/callweaver
static struct cw_filestream *au_open(FILE *f)
{
    struct cw_filestream *tmp;

    if (!(tmp = malloc(sizeof(struct cw_filestream))))
    {
        cw_log(LOG_ERROR, "Out of memory\n");
        return NULL;
    }

    memset(tmp, 0, sizeof(struct cw_filestream));
    if (check_header(f) < 0)
    {
        free(tmp);
        return NULL;
    }
    if (cw_mutex_lock(&au_lock))
    {
        cw_log(LOG_WARNING, "Unable to lock au count\n");
        free(tmp);
        return NULL;
    }
    tmp->f = f;
    cw_fr_init_ex(&tmp->fr, CW_FRAME_VOICE, CW_FORMAT_ULAW, NULL);
    tmp->fr.data = tmp->buf;
    /* datalen will vary for each frame */
    tmp->fr.src = name;

    localusecnt++;
    cw_mutex_unlock(&au_lock);
    cw_update_use_count();
    return tmp;
}
コード例 #7
0
ファイル: eapi.c プロジェクト: biappi/EasyCart
int eapi_load(easyflash_cart_t * cart, const char* filename)
{
    unsigned char buf[EAPI_SIZE + 2];
    unsigned int load_addr = 0;

    util_message("Loading EAPI '%s'...", filename);

    if (util_prgfile_load(filename, buf, EAPI_SIZE, 0, &load_addr) < 0) {
        return -1;
    }

    if (load_addr != EAPI_FILE_LOAD_ADDR) {
        util_error("load address $%04x, expecting $%04x!", load_addr, EAPI_FILE_LOAD_ADDR);
        return -1;
    }

    if (check_header(buf) != 0) {
        util_error("file '%s' doesn't have EAPI header!", filename);
        return -1;
    }

    memcpy(eapi_data, buf, EAPI_SIZE);

    cart->main_flash_state |= MAIN_STATE_HAVE_EAPI;
    return 0;
}
コード例 #8
0
ファイル: savefile.c プロジェクト: creidieki/angband
/* Try to load a savefile */
static bool try_load(ang_file *f, const struct blockinfo *loaders) {
	struct blockheader b;
	errr err;

	if (!check_header(f)) {
		note("Savefile is corrupted -- incorrect file header.");
		return FALSE;
	}

	/* Get the next block header */
	while ((err = next_blockheader(f, &b)) == 0) {
		loader_t loader = find_loader(&b, loaders);
		if (!loader) {
			note("Savefile block can't be read.");
			note("Maybe try and load the savefile in an earlier version of Angband.");
			return FALSE;
		}

		if (!load_block(f, &b, loader)) {
			note(format("Savefile corrupted - Couldn't load block %s", b.name));
			return FALSE;
		}
	}

	if (err == -1) {
		note("Savefile is corrupted -- block header mangled.");
		return FALSE;
	}

	/* XXX Reset cause of death */
	if (p_ptr->chp >= 0)
		my_strcpy(p_ptr->died_from, "(alive and well)", sizeof(p_ptr->died_from));

	return TRUE;
}
コード例 #9
0
ファイル: gsf-input-gzip.c プロジェクト: arcean/libgsf
static gboolean
init_zip (GsfInputGZip *gzip, GError **err)
{
	gsf_off_t cur_pos;

	if (Z_OK != inflateInit2 (&(gzip->stream), -MAX_WBITS)) {
		if (err != NULL)
			*err = g_error_new (gsf_input_error_id (), 0,
				"Unable to initialize zlib");
		return TRUE;
	}

	cur_pos = gsf_input_tell (gzip->source);
	if (gsf_input_seek (gzip->source, 0, G_SEEK_SET)) {
		if (err)
			*err = g_error_new (gsf_input_error_id (), 0,
					    "Failed to rewind source");
		return TRUE;
	}

	if (check_header (gzip) != FALSE) {
		if (err != NULL)
			*err = g_error_new (gsf_input_error_id (), 0,
				"Invalid gzip header");
		if (gsf_input_seek (gzip->source, cur_pos, G_SEEK_SET)) {
			g_warning ("attempt to restore position failed ??");
		}
		return TRUE;
	}

	return FALSE;
}
コード例 #10
0
void unicode_test()
{
    ar::lha::wheader head;
    head.level = 2;
    head.update_time = std::time(0);
    head.attributes = ar::msdos::attributes::read_only;
    head.path = L"\x3053\x3093\x306B\x3061\x306F/\x4F60\x597D.txt";
    head.os = 'M';

    io_ex::tmp_file archive;
    ar::basic_lzh_file_sink<
        io_ex::dont_close_device<io_ex::tmp_file>,
        fs::wpath
    > sink(io_ex::dont_close(archive));

    sink.create_entry(head);
    sink.close();
    sink.close_archive();

    io::seek(archive, 0, BOOST_IOS::beg);

    ar::basic_lzh_file_source<io_ex::tmp_file,fs::wpath> src(archive);

    BOOST_CHECK(src.next_entry());

    check_header(head, src.header());

    BOOST_CHECK(!src.next_entry());
}
コード例 #11
0
ファイル: builtin-mailinfo.c プロジェクト: Jatinpurohit/git
static int handle_commit_msg(char *line, unsigned linesize)
{
	static int still_looking = 1;
	char *endline = line + linesize;

	if (!cmitmsg)
		return 0;

	if (still_looking) {
		char *cp = line;
		if (isspace(*line)) {
			for (cp = line + 1; *cp; cp++) {
				if (!isspace(*cp))
					break;
			}
			if (!*cp)
				return 0;
		}
		if ((still_looking = check_header(cp, endline - cp, s_hdr_data, 0)) != 0)
			return 0;
	}

	/* normalize the log message to UTF-8. */
	if (metainfo_charset)
		convert_to_utf8(line, endline - line, charset);

	if (patchbreak(line)) {
		fclose(cmitmsg);
		cmitmsg = NULL;
		return 1;
	}

	fputs(line, cmitmsg);
	return 0;
}
コード例 #12
0
static int remote_read(apacket *p, atransport *t)
{
    if(usb_read(t->usb, &p->msg, sizeof(amessage))){
        D("remote usb: read terminated (message)\n");
        return -1;
    }

    fix_endians(p);

    if(check_header(p)) {
        D("remote usb: check_header failed\n");
        return -1;
    }

    if(p->msg.data_length) {
        if(usb_read(t->usb, p->data, p->msg.data_length)){
            D("remote usb: terminated (data)\n");
            return -1;
        }
    }

    if(check_data(p)) {
        D("remote usb: check_data failed\n");
        return -1;
    }

    return 0;
}
コード例 #13
0
ファイル: basic_parser.cpp プロジェクト: CFQuantum/CFQuantumd
int
basic_parser::do_header_field (char const* in, std::size_t bytes)
{
    check_header();
    field_.append (static_cast <char const*> (in), bytes);
    return 0;
}
コード例 #14
0
ファイル: udpserver.c プロジェクト: 119-org/TND
int ns__echoString(struct soap *soap, char *str, char **res)
{ /* Get Header info and setup response Header */
  if (check_header(soap))
  { printf("Malformed header\n");
    return SOAP_FAULT; /* there was a problem */
  }

  /* If message with MessageID already received, ignore it */
  if (check_received(soap->header->wsa__MessageID))
  { printf("Request message %s already received\n", soap->header->wsa__MessageID);
    return SOAP_STOP;
  }

  printf("Request message %s accepted\n", soap->header->wsa__MessageID);

  /* Check ReplyTo has Address */
  if (!soap->header->wsa__ReplyTo || !soap->header->wsa__ReplyTo->Address)
    return soap_sender_fault(soap, "No WS-Addressing ReplyTo address", NULL);
  /* Copy Header info into response Header */
  soap->header->wsa__To = soap->header->wsa__ReplyTo->Address;

  /* Add info to response Header */
  soap->header->wsa__MessageID = soap_strdup(soap, soap_int2s(soap, id_count++));
  soap->header->wsa__Action = "http://genivia.com/udp/echoStringResponse";

  /* Copy request string into response string */
  printf("Response message %s returned\n", soap->header->wsa__MessageID);
  *res = str;

  return SOAP_OK;
}
コード例 #15
0
static int remote_read(apacket *p, atransport *t)
{
    if(readx(t->sfd, &p->msg, sizeof(amessage))){
        D("remote local: read terminated (message)\n");
        return -1;
    }

    fix_endians(p);

#if 0 && defined __ppc__
    D("read remote packet: %04x arg0=%0x arg1=%0x data_length=%0x data_check=%0x magic=%0x\n",
      p->msg.command, p->msg.arg0, p->msg.arg1, p->msg.data_length, p->msg.data_check, p->msg.magic);
#endif
    if(check_header(p)) {
        D("bad header: terminated (data)\n");
        return -1;
    }

    if(readx(t->sfd, p->data, p->msg.data_length)){
        D("remote local: terminated (data)\n");
        return -1;
    }

    if(check_data(p)) {
        D("bad data: terminated (data)\n");
        return -1;
    }

    return 0;
}
コード例 #16
0
ファイル: zynqpl.c プロジェクト: Brian1013/u-boot
static void *check_data(u8 *buf, size_t bsize, u32 *swap)
{
	u32 word, p = 0; /* possition */

	/* Because buf doesn't need to be aligned let's read it by chars */
	for (p = 0; p < bsize; p++) {
		word = load_word(&buf[p], SWAP_NO);
		debug("%s: word %x %x/%x\n", __func__, word, p, (u32)&buf[p]);

		/* Find the first bitstream dummy word */
		if (word == DUMMY_WORD) {
			debug("%s: Found dummy word at position %x/%x\n",
			      __func__, p, (u32)&buf[p]);
			*swap = check_header(&buf[p]);
			if (*swap) {
				/* FIXME add full bitstream checking here */
				return &buf[p];
			}
		}
		/* Loop can be huge - support CTRL + C */
		if (ctrlc())
			return 0;
	}
	return 0;
}
コード例 #17
0
void
BestEffortSession::record_header_received(const TransportHeader& header)
{
  if (this->remote_peer_ != header.source_) return;

  check_header(header);
}
コード例 #18
0
ファイル: savefile.c プロジェクト: Daedelus01/angband
/**
 * Try to get the 'description' block from a savefile.  Fail gracefully.
 */
const char *savefile_get_description(const char *path) {
	struct blockheader b;

	ang_file *f = file_open(path, MODE_READ, FTYPE_TEXT);
	if (!f) return NULL;

	/* Blank the description */
	savefile_desc[0] = 0;

	if (!check_header(f)) {
		my_strcpy(savefile_desc, "Invalid savefile", sizeof savefile_desc);
	} else {
		while (!next_blockheader(f, &b)) {
			if (!streq(b.name, "description")) {
				skip_block(f, &b);
				continue;
			}
			load_block(f, &b, get_desc);
			break;
		}
	}

	file_close(f);
	return savefile_desc;
}
コード例 #19
0
ファイル: encrypted_secrets.c プロジェクト: DavidMulder/samba
/*
 * @brief Decrypt an attribute value.
 *
 * Returns a decrypted copy of the value, the original value is left intact.
 *
 * @param err  Pointer to an error code, set to:
 *             LDB_SUCESS               If the value was successfully decrypted
 *             LDB_ERR_OPERATIONS_ERROR If there was an error.
 *
 * @param ctx  Talloc memory context the will own the memory allocated
 * @param ldb  ldb context, to allow logging.
 * @param val  The ldb value to decrypt, not altered or freed
 * @param data The context data for this module.
 *
 * @return The decrypted ldb_val, or data_blob_null if there was an error.
 */
static struct ldb_val decrypt_value(int *err,
				    TALLOC_CTX *ctx,
				    struct ldb_context *ldb,
				    const struct ldb_val val,
				    const struct es_data *data)
{

	struct ldb_val dec;

	struct EncryptedSecret es;
	struct PlaintextSecret ps = { data_blob_null};
	int rc;
	TALLOC_CTX *frame = talloc_stackframe();

	rc = ndr_pull_struct_blob(&val,
				  frame,
				  &es,
				  (ndr_pull_flags_fn_t)
					ndr_pull_EncryptedSecret);
	if(!NDR_ERR_CODE_IS_SUCCESS(rc)) {
		ldb_asprintf_errstring(ldb,
				       "Error(%d)  unpacking encrypted secret, "
				       "data possibly corrupted or altered\n",
				       rc);
		*err = LDB_ERR_OPERATIONS_ERROR;
		TALLOC_FREE(frame);
		return data_blob_null;
	}
	if (!check_header(&es)) {
		/*
		* Header is invalid so can't be an encrypted value
		*/
		ldb_set_errstring(ldb, "Invalid EncryptedSecrets header\n");
		*err = LDB_ERR_OPERATIONS_ERROR;
		return data_blob_null;
	}
#ifdef BUILD_WITH_GNUTLS_AEAD
	gnutls_decrypt_aead(err, frame, ldb, &es, &ps, data);
#elif defined BUILD_WITH_SAMBA_AES_GCM
	samba_decrypt_aead(err, frame, ldb, &es, &ps, data);
#endif

	if (*err != LDB_SUCCESS) {
		TALLOC_FREE(frame);
		return data_blob_null;
	}

	dec = data_blob_talloc(ctx,
			       ps.cleartext.data,
			       ps.cleartext.length);
	if (dec.data == NULL) {
		TALLOC_FREE(frame);
		ldb_set_errstring(ldb, "Out of memory, copying value\n");
		*err = LDB_ERR_OPERATIONS_ERROR;
		return data_blob_null;
	}

	TALLOC_FREE(frame);
	return dec;
}
コード例 #20
0
static struct ast_filestream *wav_open(int fd)
{
	/* We don't have any header to read or anything really, but
	   if we did, it would go here.  We also might want to check
	   and be sure it's a valid file.  */
	struct ast_filestream *tmp;
	if ((tmp = malloc(sizeof(struct ast_filestream)))) {
		memset(tmp, 0, sizeof(struct ast_filestream));
		if (check_header(fd)) {
			free(tmp);
			return NULL;
		}
		if (ast_mutex_lock(&wav_lock)) {
			ast_log(LOG_WARNING, "Unable to lock wav list\n");
			free(tmp);
			return NULL;
		}
		tmp->fd = fd;
		tmp->fr.data = tmp->gsm;
		tmp->fr.frametype = AST_FRAME_VOICE;
		tmp->fr.subclass = AST_FORMAT_GSM;
		/* datalen will vary for each frame */
		tmp->fr.src = name;
		tmp->fr.mallocd = 0;
		tmp->secondhalf = 0;
		glistcnt++;
		ast_mutex_unlock(&wav_lock);
		ast_update_use_count();
	}
	return tmp;
}
コード例 #21
0
ファイル: selib_header.c プロジェクト: roccof/groink
static int l_header_dissect(lua_State *L)
{
  proto_t * p = NULL;
  header_t *h = check_header(L, -1);

  p = proto_get_byname(h->proto);
  myassert(p != NULL);

  if (p->dissect == NULL) {
    lua_pushnil(L);
    return 1;
  }

  /* Stack pos 2: traceback function */
  lua_getfield(L, LUA_REGISTRYINDEX, SE_TRACEBACK);

  /* Stack pos 3: dissect callback function */
  lua_pushcfunction(L, p->dissect);

  /* Stack pos 4: header userdata */
  lua_pushvalue(L, 1);

  if (lua_pcall(L, 1, 1, 2) != 0) {
    lua_error(L);
    return 0;
  }

  return 1;
}
コード例 #22
0
ファイル: lzh_h0_test.cpp プロジェクト: fpelliccioni/hamigaki
void symlink_test_aux(const fs::path& link, const fs::path& target, bool dir)
{
    ar::lha::header head;
    head.level = 0;
    head.update_time = std::time(0);
    head.attributes = ar::msdos::attributes::hidden;
    if (dir)
        head.attributes |= ar::msdos::attributes::directory;
    head.path = link;
    head.link_path = target;

    io_ex::tmp_file archive;
    ar::basic_lzh_file_sink<
        io_ex::dont_close_device<io_ex::tmp_file>
    > sink(io_ex::dont_close(archive));

    sink.create_entry(head);
    sink.close();
    sink.close_archive();

    io::seek(archive, 0, BOOST_IOS::beg);

    ar::basic_lzh_file_source<io_ex::tmp_file> src(archive);

    BOOST_CHECK(src.next_entry());

    check_header(head, src.header());

    BOOST_CHECK(!src.next_entry());
}
コード例 #23
0
ファイル: lzh_h0_test.cpp プロジェクト: fpelliccioni/hamigaki
void abs_path_test()
{
    ar::lha::header head;
    head.level = 0;
    head.update_time = std::time(0);
    head.attributes = ar::msdos::attributes::directory;
    head.path = "/dir/file";
    head.os = '?';

    io_ex::tmp_file archive;
    ar::basic_lzh_file_sink<
        io_ex::dont_close_device<io_ex::tmp_file>
    > sink(io_ex::dont_close(archive));

    sink.create_entry(head);
    sink.close_archive();

    io::seek(archive, 0, BOOST_IOS::beg);

    ar::basic_lzh_file_source<io_ex::tmp_file> src(archive);

    BOOST_CHECK(src.next_entry());

    check_header(head, src.header());

    BOOST_CHECK(!src.next_entry());
}
コード例 #24
0
ファイル: builtin-mailinfo.c プロジェクト: asoltys/git
static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
{
	int peek;
	fin = in;
	fout = out;

	cmitmsg = fopen(msg, "w");
	if (!cmitmsg) {
		perror(msg);
		return -1;
	}
	patchfile = fopen(patch, "w");
	if (!patchfile) {
		perror(patch);
		fclose(cmitmsg);
		return -1;
	}

	p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*p_hdr_data));
	s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(*s_hdr_data));

	do {
		peek = fgetc(in);
	} while (isspace(peek));
	ungetc(peek, in);

	/* process the email header */
	while (read_one_header_line(&line, fin))
		check_header(&line, p_hdr_data, 1);

	handle_body();
	handle_info();

	return 0;
}
コード例 #25
0
ファイル: board.c プロジェクト: guoyu07/jff
static int
check_and_write_header(int fd, int type, int readonly)
{
    file_header_t header;
    ssize_t bytes;
    char* s;

    assert(-1 != fd && ('d' == type || 'i' == type));


    s = 'd' == type ? "data" : "index";
    memset(&header, 0, sizeof(header));
    bytes = readn(fd, &header, sizeof(header));
    if (bytes != sizeof(header)) {
        ERRORV(readonly || bytes != 0, "Incomplete %s file header", s);
        if (! readonly) {
            ERRORVP(0 != write_header(fd, type),
                    "Can't write %s file header", s);
        }
    } else {
        ERRORV(0 != check_header(&header, type), "Corrupted %s file", s);
    }


    return 0;

L_error:
    return -1;
}
コード例 #26
0
ファイル: verifier.c プロジェクト: dvidelabs/flatcc
static inline int verify_table(const void *buf, uoffset_t end, uoffset_t base, uoffset_t offset, int ttl, flatcc_table_verifier_f tvf)
{
    uoffset_t vbase, vend;
    flatcc_table_verifier_descriptor_t td;

    verify((td.ttl = ttl - 1), flatcc_verify_error_max_nesting_level_reached);
    verify(check_header(end, base, offset), flatcc_verify_error_table_header_out_of_range_or_unaligned);
    td.table = base + offset;
    /* Read vtable offset - it is signed, but we want it unsigned, assuming 2's complement works. */
    vbase = td.table - read_uoffset(buf, td.table);
    verify((soffset_t)vbase >= 0 && !(vbase & (voffset_size - 1)), flatcc_verify_error_vtable_offset_out_of_range_or_unaligned);
    verify(vbase + voffset_size <= end, flatcc_verify_error_vtable_header_out_of_range);
    /* Read vtable size. */
    td.vsize = read_voffset(buf, vbase);
    vend = vbase + td.vsize;
    verify(vend <= end && !(td.vsize & (voffset_size - 1)), flatcc_verify_error_vtable_size_out_of_range_or_unaligned);
    /* Optimizes away overflow check if uoffset_t is large enough. */
    verify(uoffset_size > voffset_size || vend >= vbase, flatcc_verify_error_vtable_size_overflow);

    verify(td.vsize >= 2 * voffset_size, flatcc_verify_error_vtable_header_too_small);
    /* Read table size. */
    td.tsize = read_voffset(buf, vbase + voffset_size);
    verify(end - td.table >= td.tsize, flatcc_verify_error_table_size_out_of_range);
    td.vtable = (uint8_t *)buf + vbase;
    td.buf = buf;
    td.end = end;
    return tvf(&td);
}
コード例 #27
0
ファイル: lgwav.c プロジェクト: lgarron/lgsound2png
/*
 * Loads and sets up a wave struct.
 *
 * Returns pointer to a new wave file on success,
 * NULL on non-aborting error.
 */
struct wave* ini_wave(char* filename)
{
    struct wave* w;

    w = malloc(sizeof(wave));

    assert(open_and_read_file(filename, w) == RETURN_OKAY);
    assert(check_header(w) == RETURN_OKAY);
    assert(check_fmt_chunk(w) == RETURN_OKAY);
    assert(check_data_chunk_start(w) == RETURN_OKAY);

    w->numChannels = int_from_bytes_little_endian(w->waveFile->fmtChunk.NumChannels, 2);
    w->sampleRate = w->waveFile->fmtChunk.SampleRate;
    w->blockAlign = int_from_bytes_little_endian(w->waveFile->fmtChunk.BlockAlign, 2);
    w->bytesPerSample = int_from_bytes_little_endian(w->waveFile->fmtChunk.BitsPerSample, 2)/BITS_PER_BYTE;
    w->numSamples = (w->waveFile->dataChunkStart.Subchunk2Size)/(w->numChannels)/(w->bytesPerSample);
    w->data = (void*)(&((w->waveFile)->data));

    DPRINTF(PRINT_DIVISION);
    DPRINTF("Sanity Check\n");

    DPRINTF("w->numChannels: %d\n", w->numChannels);
    DPRINTF("w->sampleRate: %d\n", w->sampleRate);
    DPRINTF("w->blockAlign: %d\n", w->blockAlign);
    DPRINTF("w->bytesPerSample: %d\n", w->bytesPerSample);
    assert(w->bytesPerSample < sizeof(SAMPLE)); /* Otherwise, can't do computation safely. */
    DPRINTF("w->numSamples: %d\n", w->numSamples);
    DPRINTF("w->data: %p\n", w->data);

    return w;
}
コード例 #28
0
ファイル: savefile.c プロジェクト: Daedelus01/angband
/**
 * Try to load a savefile
 */
static bool try_load(ang_file *f, const struct blockinfo *loaders)
{
	struct blockheader b;
	errr err;

	if (!check_header(f)) {
		note("Savefile is corrupted -- incorrect file header.");
		return FALSE;
	}

	/* Get the next block header */
	while ((err = next_blockheader(f, &b)) == 0) {
		loader_t loader = find_loader(&b, loaders);
		if (!loader) {
			note("Savefile block can't be read.");
			note("Maybe try and load the savefile in an earlier version of Angband.");
			return FALSE;
		}

		if (!load_block(f, &b, loader)) {
			note(format("Savefile corrupted - Couldn't load block %s", b.name));
			return FALSE;
		}
	}

	if (err == -1) {
		note("Savefile is corrupted -- block header mangled.");
		return FALSE;
	}

	return TRUE;
}
コード例 #29
0
ファイル: lzh_h1_test.cpp プロジェクト: fpelliccioni/hamigaki
void fname_size_test_aux(std::size_t size)
{
    ar::lha::header head;
    head.level = 1;
    head.update_time = std::time(0);
    head.attributes = ar::msdos::attributes::read_only;
    head.path = std::string(size, 'A');
    head.os = 'M';

    io_ex::tmp_file archive;
    ar::basic_lzh_file_sink<
        io_ex::dont_close_device<io_ex::tmp_file>
    > sink(io_ex::dont_close(archive));

    sink.create_entry(head);
    sink.close();
    sink.close_archive();

    io::seek(archive, 0, BOOST_IOS::beg);

    ar::basic_lzh_file_source<io_ex::tmp_file> src(archive);

    BOOST_CHECK(src.next_entry());

    check_header(head, src.header());

    typedef std::char_traits<char> traits_type;
    BOOST_CHECK(traits_type::eq_int_type(io::get(src), traits_type::eof()));

    BOOST_CHECK(!src.next_entry());
}
コード例 #30
0
ファイル: redirect.c プロジェクト: Birdflying1005/h2o
void test_lib__handler__redirect_c()
{
    h2o_globalconf_t globalconf;
    h2o_hostconf_t *hostconf;
    h2o_pathconf_t *pathconf;

    h2o_config_init(&globalconf);
    hostconf = h2o_config_register_host(&globalconf, h2o_iovec_init(H2O_STRLIT("default")), 65535);
    pathconf = h2o_config_register_path(hostconf, "/", 0);
    h2o_redirect_register(pathconf, 0, 301, "https://example.com/bar/");

    h2o_context_init(&ctx, test_loop, &globalconf);

    {
        h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx, ctx.globalconf->hosts);
        conn->req.input.method = h2o_iovec_init(H2O_STRLIT("GET"));
        conn->req.input.path = h2o_iovec_init(H2O_STRLIT("/"));
        h2o_loopback_run_loop(conn);
        ok(conn->req.res.status == 301);
        ok(check_header(&conn->req.res, H2O_TOKEN_LOCATION, "https://example.com/bar/"));
        ok(conn->body->size != 0);
        h2o_loopback_destroy(conn);
    }
    {
        h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx, ctx.globalconf->hosts);
        conn->req.input.method = h2o_iovec_init(H2O_STRLIT("GET"));
        conn->req.input.path = h2o_iovec_init(H2O_STRLIT("/abc"));
        h2o_loopback_run_loop(conn);
        ok(conn->req.res.status == 301);
        ok(check_header(&conn->req.res, H2O_TOKEN_LOCATION, "https://example.com/bar/abc"));
        ok(conn->body->size != 0);
        h2o_loopback_destroy(conn);
    }
    {
        h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx, ctx.globalconf->hosts);
        conn->req.input.method = h2o_iovec_init(H2O_STRLIT("HEAD"));
        conn->req.input.path = h2o_iovec_init(H2O_STRLIT("/"));
        h2o_loopback_run_loop(conn);
        ok(conn->req.res.status == 301);
        ok(check_header(&conn->req.res, H2O_TOKEN_LOCATION, "https://example.com/bar/"));
        ok(conn->body->size == 0);
        h2o_loopback_destroy(conn);
    }

    h2o_context_dispose(&ctx);
    h2o_config_dispose(&globalconf);
}