~yolanda.robla/ubuntu/saucy/clamav/dep-8-tests

« back to all changes in this revision

Viewing changes to libclamav/jsparse/js-norm.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-11-02 23:27:19 UTC
  • mfrom: (0.35.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091102232719-61ay35095dhbuxfm
Tags: 0.95.3+dfsg-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Build-dep on libltdl3-dev instead of libltdl-dev for updating earlier
    releases more easily
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
};
90
90
 
91
91
struct scope {
92
 
        struct hashtable id_map;
 
92
        struct cli_hashtable id_map;
93
93
        struct scope *parent;/* hierarchy */
94
94
        struct scope *nxt;/* all scopes kept in a list so we can easily free all of them */
95
95
        enum fsm_state fsm_state;
122
122
        struct scope *s = cli_calloc(1, sizeof(*s));
123
123
        if(!s)
124
124
                return NULL;
125
 
        if(hashtab_init(&s->id_map, 10) < 0) {
 
125
        if(cli_hashtab_init(&s->id_map, 10) < 0) {
126
126
                free(s);
127
127
                return NULL;
128
128
        }
138
138
{
139
139
        struct scope* parent = s->parent;
140
140
        /* TODO: have a hashtab_destroy */
141
 
        hashtab_clear(&s->id_map);
 
141
        cli_hashtab_clear(&s->id_map);
142
142
        free(s->id_map.htable);
143
143
        free(s);
144
144
        return parent;
250
250
 
251
251
static const char* scope_declare(struct scope *s, const char *token, const size_t len, struct parser_state *state)
252
252
{
253
 
        const struct element *el = hashtab_insert(&s->id_map, token, len, state->var_uniq++);
254
 
        /* hashtab_insert either finds an already existing entry, or allocates a
 
253
        const struct cli_element *el = cli_hashtab_insert(&s->id_map, token, len, state->var_uniq++);
 
254
        /* cli_hashtab_insert either finds an already existing entry, or allocates a
255
255
         * new one, we return the allocated string */
256
256
        return el ? el->key : NULL;
257
257
}
258
258
 
259
259
static const char* scope_use(struct scope *s, const char *token, const size_t len)
260
260
{
261
 
        const struct element *el = hashtab_find(&s->id_map, token, len);
 
261
        const struct cli_element *el = cli_hashtab_find(&s->id_map, token, len);
262
262
        if(el) {
263
263
                /* identifier already found in current scope,
264
264
                 * return here to avoid overwriting uniq id */
268
268
         * Later if we find a declaration it will automatically assign a uniq ID
269
269
         * to it. If not, we'll know that we have to push ID == -1 tokens to an
270
270
         * outer scope.*/
271
 
        el = hashtab_insert(&s->id_map, token, len, -1);
 
271
        el = cli_hashtab_insert(&s->id_map, token, len, -1);
272
272
        return el ? el->key : NULL;
273
273
}
274
274
 
275
275
static long scope_lookup(struct scope *s, const char *token, const size_t len)
276
276
{
277
277
        while(s) {
278
 
                const struct element *el = hashtab_find(&s->id_map, token, len);
 
278
                const struct cli_element *el = cli_hashtab_find(&s->id_map, token, len);
279
279
                if(el && el->data != -1) {
280
280
                        return el->data;
281
281
                }
288
288
static int tokens_ensure_capacity(struct tokens *tokens, size_t cap)
289
289
{
290
290
        if(tokens->capacity < cap) {
 
291
                yystype *data;
291
292
                cap += 1024;
292
 
                tokens->data = cli_realloc(tokens->data, cap * sizeof(*tokens->data));
293
 
                if(!tokens->data)
 
293
                /* Keep old data if OOM */
 
294
                data = cli_realloc(tokens->data, cap * sizeof(*tokens->data));
 
295
                if(!data)
294
296
                        return CL_EMEM;
 
297
                tokens->data = data;
295
298
                tokens->capacity = cap;
296
299
        }
297
300
        return CL_SUCCESS;
299
302
 
300
303
static int add_token(struct parser_state *state, const yystype *token)
301
304
{
302
 
        if(tokens_ensure_capacity(&state->tokens, state->tokens.cnt + 1) < 0)
 
305
        if(tokens_ensure_capacity(&state->tokens, state->tokens.cnt + 1))
303
306
                return -1;
304
307
        state->tokens.data[state->tokens.cnt++] = *token;
305
308
        return 0;
502
505
 
503
506
static inline char *textbuffer_done(yyscan_t scanner)
504
507
{
505
 
        /* free unusued memory */
506
 
        char *str = cli_realloc(scanner->buf.data, scanner->buf.pos);
507
 
        if(!str) {
508
 
                str = scanner->buf.data;
509
 
        }
510
 
        scanner->yytext = str;
511
 
        scanner->yylen = scanner->buf.pos - 1;
512
 
        memset(&scanner->buf, 0, sizeof(scanner->buf));
513
 
        return str;
 
508
       char *str = cli_realloc(scanner->buf.data, scanner->buf.pos);
 
509
       if(!str) {
 
510
               str = scanner->buf.data;
 
511
       }
 
512
       scanner->yytext = str;
 
513
       scanner->yylen = scanner->buf.pos - 1;
 
514
       memset(&scanner->buf, 0, sizeof(scanner->buf));
 
515
       return str;
514
516
}
515
517
 
516
518
#define MODULE "JS-Norm: "
533
535
        for(i=start;i<end;i++) {
534
536
                free_token(&dst->data[i]);
535
537
        }
536
 
        if(tokens_ensure_capacity(dst, dst->cnt - (end-start) + len) < 0)
 
538
        if(tokens_ensure_capacity(dst, dst->cnt - (end-start) + len))
537
539
                return CL_EMEM;
538
540
        memmove(&dst->data[start+len], &dst->data[end], (dst->cnt - end) * sizeof(dst->data[0]));
539
541
        if(with && len > 0) {
547
549
{
548
550
        if(!dst || !src)
549
551
                return CL_ENULLARG;
550
 
        if(tokens_ensure_capacity(dst, dst->cnt + src->cnt) == -1)
 
552
        if(tokens_ensure_capacity(dst, dst->cnt + src->cnt))
551
553
                return CL_EMEM;
552
554
        cli_dbgmsg(MODULE "Appending %lu tokens\n", src->cnt);
553
555
        memcpy(&dst->data[dst->cnt], src->data, src->cnt * sizeof(dst->data[0]));
1127
1129
                                                free_token(&state->tokens.data[--state->tokens.cnt]);
1128
1130
 
1129
1131
                                                str = cli_realloc(str, str_len + leng + 1);
 
1132
                                                if (!str)
 
1133
                                                    break;
1130
1134
                                                strncpy(str+str_len, text, leng);
1131
1135
                                                str[str_len + leng] = '\0';
1132
1136
                                                TOKEN_SET(prev_string, string, str);
1254
1258
static void textbuf_clean(struct text_buffer *buf)
1255
1259
{
1256
1260
        if(buf->capacity > BUF_KEEP_SIZE) {
1257
 
                buf->data = cli_realloc(buf->data, BUF_KEEP_SIZE);
 
1261
                char *data= cli_realloc(buf->data, BUF_KEEP_SIZE);
 
1262
                if (data)
 
1263
                    buf->data = data;
1258
1264
                buf->capacity = BUF_KEEP_SIZE;
1259
1265
        }
1260
1266
        buf->pos = 0;
1281
1287
                len = scanner->insize - scanner->pos;
1282
1288
        cli_textbuffer_append_normalize(&scanner->buf, start, len);
1283
1289
        if(end) {
 
1290
                char *str;
1284
1291
                /* skip over end quote */
1285
1292
                scanner->pos += len + 1;
1286
1293
                textbuffer_putc(&scanner->buf, '\0');
1287
 
                TOKEN_SET(lvalp, string, textbuffer_done(scanner));
 
1294
                str = textbuffer_done(scanner);
 
1295
                if (str) {
 
1296
                    TOKEN_SET(lvalp, string, str);
 
1297
                } else {
 
1298
                    TOKEN_SET(lvalp, cstring, "");
 
1299
                }
1288
1300
                scanner->state = Initial;
1289
1301
                assert(lvalp->val.string);
1290
1302
                return TOK_StringLiteral;
1334
1346
                scanner->pos--;
1335
1347
                textbuffer_putc(&scanner->buf, '\0');
1336
1348
                scanner->state = Initial;
 
1349
                if (!scanner->buf.data)
 
1350
                        return 0;
1337
1351
                if(is_float) {
1338
1352
                        TOKEN_SET(lvalp, dval, atof(scanner->buf.data));
1339
1353
                        return TOK_NumericFloat;
1438
1452
 
1439
1453
static const char *yyget_text(yyscan_t scanner)
1440
1454
{
1441
 
        assert(scanner->buf.data || scanner->yytext);
1442
 
        return scanner->yytext ? scanner->yytext : scanner->buf.data;
 
1455
    return scanner->yytext ? scanner->yytext :  scanner->buf.data;
1443
1456
}
1444
1457
 
1445
1458
static int yyget_leng(yyscan_t scanner)
1446
1459
{
1447
1460
        /* we have a \0 too */
1448
 
        return scanner->yylen ? scanner->yylen : (scanner->buf.pos > 0 ? scanner->buf.pos - 1 : 0);
 
1461
        return scanner->yylen ? scanner->yylen: (scanner->buf.pos > 0 ? scanner->buf.pos - 1 : 0);
1449
1462
}
1450
1463
 
1451
1464
static int yylex(YYSTYPE *lvalp, yyscan_t  scanner)