2 * This file is part of ltrace.
3 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
31 zero_callback_max(struct value *ret_value, struct value *lhs,
32 struct value_dict *arguments,
33 size_t max, void *data)
36 for (i = 0; i < max; ++i) {
38 if (value_init_element(&element, lhs, i) < 0)
41 int zero = value_is_zero(&element, arguments);
43 value_destroy(&element);
49 struct arg_type_info *long_type = type_get_simple(ARGTYPE_LONG);
50 value_init_detached(ret_value, NULL, long_type, 0);
51 value_set_word(ret_value, i);
55 /* LHS->zero(RHS). Looks for a length of zero-terminated array, but
56 * looks no further than first RHS bytes. */
58 zero_callback(struct value *ret_value, struct value *lhs,
59 struct value *rhs, struct value_dict *arguments, void *data)
62 if (value_extract_word(rhs, &l, arguments) < 0)
65 /* It might just be a positive value >2GB, but that's
67 report_global_error("maximum array length seems negative");
68 size_t max = (size_t)l;
69 return zero_callback_max(ret_value, lhs, arguments, max, data);
72 /* LHS->zero. Looks for a length of zero-terminated array, without
75 zero1_callback(struct value *ret_value, struct value *lhs,
76 struct value_dict *arguments, void *data)
78 return zero_callback_max(ret_value, lhs, arguments, (size_t)-1, data);
82 build_zero_w_arg(struct expr_node *expr, int own)
84 struct expr_node *e_z = malloc(sizeof(*e_z));
88 expr_init_cb2(e_z, &zero_callback,
89 expr_self(), 0, expr, own, NULL);
96 static struct expr_node *node = NULL;
98 node = malloc(sizeof(*node));
100 error(1, errno, "malloc expr_node_zero");
101 expr_init_cb1(node, &zero1_callback,
102 expr_self(), 0, (void *)-1);