// ind debug mode we have our own main function int main() { char buf[1024]; //snprintf(buf,sizeof(buf), "SELECT * FROM users WHERE laston=unix_timestamp()+10*20+fn() AND user_level>1 ORDER BY userid ASC"); snprintf(buf,sizeof(buf), "SELECT * FROM users WHERE laston=1"); scan_buffer(buf); snprintf(buf,sizeof(buf), "select 1 from user where 1 -- commnent"); scan_buffer(buf); std::string s; while (std::cin) { memset(p_risk, 0, sizeof(struct query_risk)); std::getline(std::cin, s); //std::cout << "line: " << s << std::endl; scan_buffer(s.c_str()); free_sql_strings(); free_expressions(); if (p_risk->has_tautology) { printf("query has tautology\n"); } } //free_sql_strings(); //free_expressions(); return 1; }
static int mpeg4_unpack_bframes_init(AVBSFContext *ctx) { if (ctx->par_in->extradata) { int pos_p_ext = -1; scan_buffer(ctx->par_in->extradata, ctx->par_in->extradata_size, &pos_p_ext, NULL, NULL); if (pos_p_ext >= 0) { av_log(ctx, AV_LOG_DEBUG, "Updating DivX userdata (remove trailing 'p') in extradata.\n"); ctx->par_out->extradata[pos_p_ext] = '\0'; } } return 0; }
bool query_parse(struct query_risk * q_risk, SQLPatterns * sql_patterns, const char * q) { p_risk = q_risk; //bzero(q_risk, sizeof(struct query_risk)); memset(q_risk, 0, sizeof(struct query_risk)); patterns = sql_patterns; #ifndef WIN32 scan_buffer(q); #endif free_sql_strings(); free_expressions(); return true; }
/* Calculate the line number in buffer B at position POS. If CACHEP is non-zero, initialize and facilitate the line-number cache. The line number of the first line is 0. If narrowing is in effect, count the lines are counted from the beginning of the visible portion of the buffer. The cache works as follows: To calculate the line number, we need two positions: position of point (POS) and the position from which to count newlines (BEG). We start by setting BEG to BUF_BEGV. If this would require too much searching (i.e. pos - BUF_BEGV > LINE_NUMBER_FAR), try to find a closer position in the ring. If it is found, use that position for BEG, and increment the line number appropriately. If the calculation (with or without the cache lookup) required more than LINE_NUMBER_FAR characters of traversal, update the cache. */ EMACS_INT buffer_line_number (struct buffer *b, Charbpos pos, Boolint cachep, Boolint respect_narrowing) { Charbpos beg = respect_narrowing ? BUF_BEGV (b) : BUF_BEG (b); EMACS_INT cached_lines = 0; EMACS_INT shortage, line; if ((pos > beg ? pos - beg : beg - pos) <= LINE_NUMBER_FAR) cachep = 0; if (cachep && (respect_narrowing || BUF_BEG (b) == BUF_BEGV (b))) { if (NILP (b->text->line_number_cache)) allocate_line_number_cache (b); /* If we don't know the line number of BUF_BEGV, calculate it now. */ if (XFIXNUM (LINE_NUMBER_BEGV (b)) == -1) { LINE_NUMBER_BEGV (b) = Qzero; /* #### This has a side-effect of changing the cache. */ LINE_NUMBER_BEGV (b) = make_fixnum (buffer_line_number (b, BUF_BEGV (b), 1, 0)); } cached_lines = XFIXNUM (LINE_NUMBER_BEGV (b)); get_nearest_line_number (b, &beg, pos, &cached_lines); } scan_buffer (b, '\n', beg, pos, pos > beg ? MOST_POSITIVE_FIXNUM : -MOST_POSITIVE_FIXNUM, &shortage, 0); line = MOST_POSITIVE_FIXNUM - shortage; if (beg > pos) line = -line; line += cached_lines; if (cachep && (respect_narrowing || BUF_BEG (b) == BUF_BEGV (b))) { /* If too far, update the cache. */ if ((pos > beg ? pos - beg : beg - pos) > LINE_NUMBER_FAR) add_position_to_cache (b, pos, line); /* Account for narrowing. If cache is not used, this is unnecessary, because we counted from BUF_BEGV anyway. */ line -= XFIXNUM (LINE_NUMBER_BEGV (b)); } return line; }
/* Invalidate the cache positions after FROM, if the region to be deleted contains a newline. If the region-to-be-deleted is larger than LINE_NUMBER_LARGE_STRING, invalidate the cache positions after FROM without unconditionally. This will do nothing if the cache is uninitialized. */ void delete_invalidate_line_number_cache (struct buffer *b, Charbpos from, Charbpos to) { if (NILP (b->text->line_number_cache)) return; if ((to - from) > LINE_NUMBER_LARGE_STRING) invalidate_line_number_cache (b, from); else { EMACS_INT shortage; scan_buffer (b, '\n', from, to, 1, &shortage, 0); if (!shortage) invalidate_line_number_cache (b, from); } }
static void setup_context_cache (struct buffer *buf, Bufpos pt) { int recomputed_start_point = 0; /* This function can GC */ if (context_cache.buffer != buf || pt < context_cache.start_point) { start_over: if (font_lock_debug) stderr_out ("reset context cache\n"); /* OK, completely invalid. */ reset_context_cache (&context_cache); reset_context_cache (&bol_context_cache); } if (!context_cache.buffer) { /* Need to recompute the start point. */ if (font_lock_debug) stderr_out ("recompute start\n"); context_cache.start_point = beginning_of_defun (buf, pt); recomputed_start_point = 1; bol_context_cache.start_point = context_cache.start_point; bol_context_cache.buffer = context_cache.buffer = buf; } if (context_cache.end_point < context_cache.start_point) { /* Need to recompute the end point. */ if (font_lock_debug) stderr_out ("recompute end\n"); context_cache.end_point = end_of_defun (buf, context_cache.start_point); bol_context_cache.end_point = context_cache.end_point; } if (bol_context_cache.cur_point == 0 || pt < bol_context_cache.cur_point) { if (font_lock_debug) stderr_out ("reset to start\n"); if (pt > context_cache.end_point /* 3000 is some arbitrary delta but seems reasonable; about the size of a reasonable function */ && pt - context_cache.end_point > 3000) /* If we're far past the end of the top level form, don't trust it; recompute it. */ { /* But don't get in an infinite loop doing this. If we're really far past the end of the top level form, try to compute a pseudo-top-level form. */ if (recomputed_start_point) context_cache.needs_its_head_reexamined = 1; else /* force recomputation */ goto start_over; } /* Go to the nearest end of the top-level form that's before us. */ if (pt > context_cache.end_point) pt = context_cache.end_point; else pt = context_cache.start_point; /* Reset current point to start of buffer. */ context_cache.cur_point = pt; context_cache.context = context_none; context_cache.ccontext = ccontext_none; context_cache.style = comment_style_none; context_cache.scontext = '\000'; context_cache.depth = 0; /* #### shouldn't this be checking the character's syntax instead of explicitly testing for backslash characters? */ context_cache.backslash_p = ((pt > 1) && (BUF_FETCH_CHAR (buf, pt - 1) == '\\')); /* Note that the BOL context cache may not be at the beginning of the line, but that should be OK, nobody's checking. */ bol_context_cache = context_cache; return; } else if (pt < context_cache.cur_point) { if (font_lock_debug) stderr_out ("reset to bol\n"); /* bol cache is OK but current_cache is not. */ context_cache = bol_context_cache; return; } else if (pt <= context_cache.end_point) { if (font_lock_debug) stderr_out ("everything is OK\n"); /* in same top-level form. */ return; } { /* OK, we're past the end of the top-level form. */ Bufpos maxpt = max (context_cache.end_point, context_cache.cur_point); #if 0 int shortage; #endif if (font_lock_debug) stderr_out ("past end\n"); if (pt <= maxpt) /* OK, fine. */ return; #if 0 /* This appears to cause huge slowdowns in files which have no top-level forms. In any case, it's not really necessary that we know for sure the top-level form we're in; if we're in a form but the form we have recorded is the previous one, it will be OK. */ scan_buffer (buf, '\n', maxpt, pt, 1, &shortage, 1); if (!shortage) /* If there was a newline in the region past the known universe, we might be inside another top-level form, so start over. Otherwise, we're outside of any top-level forms and we know the one directly before us, so it's OK. */ goto start_over; #endif } }
static int mpeg4_unpack_bframes_filter(AVBSFContext *ctx, AVPacket *out) { UnpackBFramesBSFContext *s = ctx->priv_data; int pos_p = -1, nb_vop = 0, pos_vop2 = -1, ret = 0; AVPacket *in; ret = ff_bsf_get_packet(ctx, &in); if (ret < 0) return ret; scan_buffer(in->data, in->size, &pos_p, &nb_vop, &pos_vop2); av_log(ctx, AV_LOG_DEBUG, "Found %d VOP startcode(s) in this packet.\n", nb_vop); if (pos_vop2 >= 0) { if (s->b_frame_buf) { av_log(ctx, AV_LOG_WARNING, "Missing one N-VOP packet, discarding one B-frame.\n"); av_freep(&s->b_frame_buf); s->b_frame_buf_size = 0; } /* store the packed B-frame in the BSFContext */ s->b_frame_buf_size = in->size - pos_vop2; s->b_frame_buf = create_new_buffer(in->data + pos_vop2, s->b_frame_buf_size); if (!s->b_frame_buf) { s->b_frame_buf_size = 0; av_packet_free(&in); return AVERROR(ENOMEM); } } if (nb_vop > 2) { av_log(ctx, AV_LOG_WARNING, "Found %d VOP headers in one packet, only unpacking one.\n", nb_vop); } if (nb_vop == 1 && s->b_frame_buf) { /* use frame from BSFContext */ ret = av_packet_copy_props(out, in); if (ret < 0) { av_packet_free(&in); return ret; } ret = av_packet_from_data(out, s->b_frame_buf, s->b_frame_buf_size); if (ret < 0) { av_packet_free(&in); return ret; } if (in->size <= MAX_NVOP_SIZE) { /* N-VOP */ av_log(ctx, AV_LOG_DEBUG, "Skipping N-VOP.\n"); s->b_frame_buf = NULL; s->b_frame_buf_size = 0; } else { /* copy packet into BSFContext */ s->b_frame_buf_size = in->size; s->b_frame_buf = create_new_buffer(in->data, in->size); if (!s->b_frame_buf) { s->b_frame_buf_size = 0; av_packet_unref(out); av_packet_free(&in); return AVERROR(ENOMEM); } } } else if (nb_vop >= 2) { /* use first frame of the packet */ av_packet_move_ref(out, in); out->size = pos_vop2; } else if (pos_p >= 0) { av_log(ctx, AV_LOG_DEBUG, "Updating DivX userdata (remove trailing 'p').\n"); av_packet_move_ref(out, in); /* remove 'p' (packed) from the end of the (DivX) userdata string */ out->data[pos_p] = '\0'; } else { /* copy packet */ av_packet_move_ref(out, in); } av_packet_free(&in); return 0; }
void FABIO_READ_SKIP_S(const int* fdp, const int* offsetp, const int* skipp, float sp[], const int* countp) { int fd = *fdp; char c; size_t count = *countp; off_t offset = *offsetp; off_t skip = *skipp; int i,j; char buffer[1024]; int border[8]; int swap_bytes = 0; if ( lseek(fd, offset, SEEK_SET) < 0 ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to seek to %ld: %s\n", offset, strerror(errno)); exit(1); } for (i=0;;i++) { if ( read(fd, &c, 1) != 1 ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to read a char: %s\n", strerror(errno)); exit(1); } if ( c == '\n' ) break; if ( i == sizeof(buffer) ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed FAB header\n"); exit(1); } buffer[i] = c; } buffer[i] = 0; i = scan_buffer(buffer, border); if ( i == FABIO_DOUBLE ) { double* dp; if ( (dp = (double *) malloc(count*sizeof(double))) == NULL) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to allocate sp\n"); exit(1); } /* should be positioned to read the doubles */ if ( skip && lseek(fd, skip*sizeof(double), SEEK_CUR) < 0 ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to seek to comp %ld: %s\n", offset, strerror(errno)); exit(1); } if ( count*sizeof(double) != read(fd, dp, count*sizeof(double)) ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to read %ld doubles: %s\n", (long)count, strerror(errno)); exit(1); } for ( j = 0; j < 8; ++j ) { if (border[j] != norder_d[j] ) { swap_bytes = 1; break; } } if ( swap_bytes ) { unsigned char* cdp = (unsigned char*)dp; for ( i = 0; i < count; i++ ) { unsigned char t[8]; for ( j = 0; j < 8; j++ ) { t[j] = cdp[border[j]-1]; } for ( j = 0; j < 8; j++ ) { cdp[j] = t[norder_d[j]-1]; } cdp += 8; } } free(dp); for ( i = 0; i < count; i++ ) { if ( dp[i] > FLT_MAX ) sp[i] = FLT_MAX; else if ( dp[i] < -FLT_MAX ) sp[i] = -FLT_MAX; else sp[i] = (float)dp[i]; } } else if ( i == FABIO_SINGLE ) { /* should be positioned to read the doubles */ if ( skip && lseek(fd, skip*sizeof(float), SEEK_CUR) < 0 ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to seek to comp %ld: %s\n", offset, strerror(errno)); exit(1); } if ( count*sizeof(float) != read(fd, sp, count*sizeof(float)) ) { fprintf(stderr, "FABIO_READ_SKIP_S: failed to read %ld doubles: %s\n", (long)count, strerror(errno)); exit(1); } for ( j = 0; j < 4; ++j ) { if (border[j] != norder_f[j] ) { swap_bytes = 1; break; } } if ( swap_bytes ) { unsigned char* csp = (unsigned char*)sp; for ( i = 0; i < count; i++ ) { unsigned char t[4]; for ( j = 0; j < 4; j++ ) { t[j] = csp[border[j]-1]; } for ( j = 0; j < 4; j++ ) { csp[j] = t[norder_f[j]-1]; } csp += 4; } } } }
static int mpeg4_unpack_bframes_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe) { UnpackBFramesBSFContext *ctx = bsfc->priv_data; int pos_p = -1, nb_vop = 0, pos_vop2 = -1, ret = 0; if (avctx->codec_id != AV_CODEC_ID_MPEG4) { av_log(avctx, AV_LOG_ERROR, "The mpeg4_unpack_bframes bitstream filter is only useful for mpeg4.\n"); return AVERROR(EINVAL); } if (!ctx->updated_extradata && avctx->extradata) { int pos_p_ext = -1; scan_buffer(avctx->extradata, avctx->extradata_size, &pos_p_ext, NULL, NULL); if (pos_p_ext >= 0) { av_log(avctx, AV_LOG_DEBUG, "Updating DivX userdata (remove trailing 'p') in extradata.\n"); avctx->extradata[pos_p_ext] = '\0'; } ctx->updated_extradata = 1; } scan_buffer(buf, buf_size, &pos_p, &nb_vop, &pos_vop2); av_log(avctx, AV_LOG_DEBUG, "Found %d VOP startcode(s) in this packet.\n", nb_vop); if (pos_vop2 >= 0) { if (ctx->b_frame_buf) { av_log(avctx, AV_LOG_WARNING, "Missing one N-VOP packet, discarding one B-frame.\n"); av_freep(&ctx->b_frame_buf); ctx->b_frame_buf_size = 0; } /* store the packed B-frame in the BSFContext */ ctx->b_frame_buf_size = buf_size - pos_vop2; ctx->b_frame_buf = create_new_buffer(buf + pos_vop2, ctx->b_frame_buf_size); if (!ctx->b_frame_buf) { ctx->b_frame_buf_size = 0; return AVERROR(ENOMEM); } } if (nb_vop > 2) { av_log(avctx, AV_LOG_WARNING, "Found %d VOP headers in one packet, only unpacking one.\n", nb_vop); } if (nb_vop == 1 && ctx->b_frame_buf) { /* use frame from BSFContext */ *poutbuf = ctx->b_frame_buf; *poutbuf_size = ctx->b_frame_buf_size; /* the output buffer is distinct from the input buffer */ ret = 1; if (buf_size <= MAX_NVOP_SIZE) { /* N-VOP */ av_log(avctx, AV_LOG_DEBUG, "Skipping N-VOP.\n"); ctx->b_frame_buf = NULL; ctx->b_frame_buf_size = 0; } else { /* copy packet into BSFContext */ ctx->b_frame_buf_size = buf_size; ctx->b_frame_buf = create_new_buffer(buf , buf_size); if (!ctx->b_frame_buf) { ctx->b_frame_buf_size = 0; av_freep(poutbuf); *poutbuf_size = 0; return AVERROR(ENOMEM); } } } else if (nb_vop >= 2) { /* use first frame of the packet */ *poutbuf = (uint8_t *) buf; *poutbuf_size = pos_vop2; } else if (pos_p >= 0) { av_log(avctx, AV_LOG_DEBUG, "Updating DivX userdata (remove trailing 'p').\n"); *poutbuf_size = buf_size; *poutbuf = create_new_buffer(buf, buf_size); if (!*poutbuf) { *poutbuf_size = 0; return AVERROR(ENOMEM); } /* remove 'p' (packed) from the end of the (DivX) userdata string */ (*poutbuf)[pos_p] = '\0'; /* the output buffer is distinct from the input buffer */ ret = 1; } else { /* copy packet */ *poutbuf = (uint8_t *) buf; *poutbuf_size = buf_size; } return ret; }