summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
057f189)
When there is no error checking, use bprintf or bvprintf instead of
asprintf or vasprintf.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8451
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
gras_msg_handleall(5); /* friends, we're ready. Come and play */
if (xbt_dynar_length(group) < 2) {
gras_msg_handleall(5); /* friends, we're ready. Come and play */
if (xbt_dynar_length(group) < 2) {
- CRITICAL1("Not enough peers arrived. Expected 2 got %ld",
- xbt_dynar_length(group));
+ char *msg = bprintf("Not enough peers arrived. Expected 2 got %ld",
+ xbt_dynar_length(group));
amok_pm_group_shutdown("bandwidth");
amok_pm_group_shutdown("bandwidth");
}
h1 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 0);
h2 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 1);
}
h1 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 0);
h2 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 1);
#endif
#include <stdio.h>
#endif
#endif
#include <stdio.h>
#endif
/* snprintf related functions */
/** @addtogroup XBT_str
/* snprintf related functions */
/** @addtogroup XBT_str
* See asprintf()
*/
#if defined(SIMGRID_NEED_VASPRINTF)||defined(DOXYGEN)
* See asprintf()
*/
#if defined(SIMGRID_NEED_VASPRINTF)||defined(DOXYGEN)
XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap);
#endif
/** @brief print to allocated string
*
XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap);
#endif
/** @brief print to allocated string
*
- * Works just like asprintf(), but returns a pointer to the newly created string
+ * Works just like vasprintf(), but returns a pointer to the newly
+ * created string, or aborts on error.
+ */
+XBT_PUBLIC(char *) bvprintf(const char *fmt, va_list ap);
+/** @brief print to allocated string
+ *
+ * Works just like asprintf(), but returns a pointer to the newly
+ * created string, or aborts on error.
*/
XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2);
/** @} */
*/
XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2);
/** @} */
char *buffname;
gras_datadesc_type_t res;
char *buffname;
gras_datadesc_type_t res;
- if (asprintf(&buffname, "s_xbt_dynar_of_%s", elm_t->name) == -1)
- xbt_die("asprintf failed");
+ buffname = bprintf("s_xbt_dynar_of_%s", elm_t->name);
res = gras_datadesc_struct(buffname);
res = gras_datadesc_struct(buffname);
/* build a ref to it */
free(buffname);
/* build a ref to it */
free(buffname);
- if (asprintf(&buffname, "xbt_dynar_of_%s", elm_t->name) == -1)
- xbt_die("asprintf failed");
+ buffname = bprintf("xbt_dynar_of_%s", elm_t->name);
res = gras_datadesc_ref(buffname, res);
free(buffname);
return res;
res = gras_datadesc_ref(buffname, res);
free(buffname);
return res;
char *buffname;
gras_datadesc_type_t res;
char *buffname;
gras_datadesc_type_t res;
- if (asprintf(&buffname, "s_xbt_matrix_t(%s)", elm_t->name) == -1)
- xbt_die("asprintf failed");
+ buffname = bprintf("s_xbt_matrix_t(%s)", elm_t->name);
res = gras_datadesc_struct(buffname);
gras_datadesc_struct_append(res, "lines",
res = gras_datadesc_struct(buffname);
gras_datadesc_struct_append(res, "lines",
/* build a ref to it */
free(buffname);
/* build a ref to it */
free(buffname);
- if (asprintf(&buffname, "xbt_matrix_t(%s)", elm_t->name) == -1)
- xbt_die("asprintf failed");
+ buffname = bprintf("xbt_matrix_t(%s)", elm_t->name);
res = gras_datadesc_ref(buffname, res);
free(buffname);
return res;
res = gras_datadesc_ref(buffname, res);
free(buffname);
return res;
xbt_swag_foreach(process, simix_global->process_list) {
char *who, *who2;
xbt_swag_foreach(process, simix_global->process_list) {
char *who, *who2;
- if (asprintf(&who, "%s on %s: %s",
- process->name,
- process->smx_host->name,
- (process->blocked) ? "[BLOCKED] "
- : ((process->suspended) ? "[SUSPENDED] " : "")) == -1)
- xbt_die("asprintf failed");
+ who = bprintf("%s on %s: %s",
+ process->name,
+ process->smx_host->name,
+ (process->blocked) ? "[BLOCKED] "
+ : ((process->suspended) ? "[SUSPENDED] " : ""));
if (process->mutex) {
who2 =
if (process->mutex) {
who2 =
-#include "xbt/sysdep.h" /* vasprintf */
+#include "xbt/sysdep.h" /* bvprintf */
#include "xbt/cunit.h"
#include "xbt/dynar.h"
#include "xbt/cunit.h"
#include "xbt/dynar.h"
{
xbt_test_suite_t suite = xbt_new0(struct s_xbt_test_suite, 1);
va_list ap;
{
xbt_test_suite_t suite = xbt_new0(struct s_xbt_test_suite, 1);
va_list ap;
if (!_xbt_test_suites)
_xbt_test_suites =
xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free);
va_start(ap, fmt);
if (!_xbt_test_suites)
_xbt_test_suites =
xbt_dynar_new(sizeof(xbt_test_suite_t), xbt_test_suite_free);
va_start(ap, fmt);
- vres = vasprintf(&suite->title, fmt, ap);
+ suite->title = bvprintf(fmt, ap);
suite->units =
xbt_dynar_new(sizeof(xbt_test_unit_t), &xbt_test_unit_free);
va_end(ap);
suite->units =
xbt_dynar_new(sizeof(xbt_test_unit_t), &xbt_test_unit_free);
va_end(ap);
char *bufname;
va_list ap;
char *bufname;
va_list ap;
if (_xbt_test_suites)
xbt_dynar_foreach(_xbt_test_suites, it_suite, suite)
if (_xbt_test_suites)
xbt_dynar_foreach(_xbt_test_suites, it_suite, suite)
return suite;
va_start(ap, fmt);
return suite;
va_start(ap, fmt);
- vres = vasprintf(&bufname, fmt, ap);
+ bufname = bvprintf(fmt, ap);
va_end(ap);
suite = xbt_test_suite_new(name, bufname, NULL);
free(bufname);
va_end(ap);
suite = xbt_test_suite_new(name, bufname, NULL);
free(bufname);
{
xbt_test_unit_t unit;
va_list ap;
{
xbt_test_unit_t unit;
va_list ap;
xbt_assert(suite);
xbt_assert(func);
xbt_assert(suite);
xbt_assert(func);
unit = xbt_new0(struct s_xbt_test_unit, 1);
va_start(ap, fmt);
unit = xbt_new0(struct s_xbt_test_unit, 1);
va_start(ap, fmt);
- vres = vasprintf(&unit->title, fmt, ap);
+ unit->title = bvprintf(fmt, ap);
va_end(ap);
unit->name = (char *) name;
unit->func = func;
va_end(ap);
unit->name = (char *) name;
unit->func = func;
unsigned int it_unit, it_test, it_log;
int first = 1; /* for result pretty printing */
unsigned int it_unit, it_test, it_log;
int first = 1; /* for result pretty printing */
if (suite == NULL)
return 0;
if (suite == NULL)
return 0;
unit->test_expect = 0;
/* display unit title */
unit->test_expect = 0;
/* display unit title */
- vres =
- asprintf(&cp,
- " Unit: %s ......................................"
+ cp = bprintf(" Unit: %s ......................................"
"......................................", unit->title);
cp[70] = '\0';
fprintf(stderr, "%s", cp);
"......................................", unit->title);
cp[70] = '\0';
fprintf(stderr, "%s", cp);
xbt_test_unit_t unit = _xbt_test_current_unit;
xbt_test_test_t test;
va_list ap;
xbt_test_unit_t unit = _xbt_test_current_unit;
xbt_test_test_t test;
va_list ap;
xbt_assert(unit);
xbt_assert(fmt);
test = xbt_new0(struct s_xbt_test_test, 1);
va_start(ap, fmt);
xbt_assert(unit);
xbt_assert(fmt);
test = xbt_new0(struct s_xbt_test_test, 1);
va_start(ap, fmt);
- vres = vasprintf(&test->title, fmt, ap);
+ test->title = bvprintf(fmt, ap);
va_end(ap);
test->failed = 0;
test->expected_failure = 0;
va_end(ap);
test->failed = 0;
test->expected_failure = 0;
xbt_test_test_t test;
xbt_test_log_t log;
va_list ap;
xbt_test_test_t test;
xbt_test_log_t log;
va_list ap;
xbt_assert(unit);
xbt_assert(fmt);
xbt_assert(unit);
xbt_assert(fmt);
log = xbt_new(struct s_xbt_test_log, 1);
va_start(ap, fmt);
log = xbt_new(struct s_xbt_test_log, 1);
va_start(ap, fmt);
- vres = vasprintf(&log->text, fmt, ap);
+ log->text = bvprintf(fmt, ap);
va_end(ap);
log->file = file;
log->line = line;
va_end(ap);
log->file = file;
log->line = line;
xbt_test_test_t test;
xbt_test_log_t log;
va_list ap;
xbt_test_test_t test;
xbt_test_log_t log;
va_list ap;
xbt_assert(unit);
xbt_assert(fmt);
xbt_assert(unit);
xbt_assert(fmt);
log = xbt_new(struct s_xbt_test_log, 1);
va_start(ap, fmt);
log = xbt_new(struct s_xbt_test_log, 1);
va_start(ap, fmt);
- vres = vasprintf(&log->text, fmt, ap);
+ log->text = bvprintf(fmt, ap);
va_end(ap);
log->file = file;
log->line = line;
va_end(ap);
log->file = file;
log->line = line;
/* FIXME: better place */
#include "xbt/sysdep.h"
/* FIXME: better place */
#include "xbt/sysdep.h"
+char *bvprintf(const char *fmt, va_list ap)
+{
+ char *res;
+
+ if (vasprintf(&res, fmt, ap) < 0) {
+ /* Do not want to use xbt_die() here, as it uses the logging
+ * infrastucture and may fail to allocate memory too. */
+ fprintf(stderr, "bprintf: vasprintf failed. Aborting.\n");
+ abort();
+ }
+ return res;
+}
+
char *bprintf(const char *fmt, ...)
{
va_list ap;
char *res;
char *bprintf(const char *fmt, ...)
{
va_list ap;
char *res;
-
- len = vasprintf(&res, fmt, ap);
-
+ res = bvprintf(fmt, ap);
va_end(ap);
return res;
}
va_end(ap);
return res;
}
char *q = l->data;
char *tmp;
char *tmp2;
char *q = l->data;
char *tmp;
char *tmp2;
- int vres; /* shut gcc up, but ignored */
while (*q != '\0') {
if (*q == '%') {
while (*q != '\0') {
if (*q == '%') {
break;
case 'm': /* user-provided message; LOG4J compliant */
break;
case 'm': /* user-provided message; LOG4J compliant */
- vres = vasprintf(&tmp2, fmt, ev->ap_copy);
+ tmp2 = bvprintf(fmt, ev->ap_copy);
append1("%s", "%.*s", tmp2);
free(tmp2);
break;
append1("%s", "%.*s", tmp2);
free(tmp2);
break;
xbt_strbuff_append(buff, loc_buff);
xbt_strbuff_append(buff, loc_buff);
- if (vasprintf(&p, fmt, ev->ap_copy) == -1)
- xbt_die("vasprintf failed");
+ p = bvprintf(fmt, ev->ap_copy);
xbt_strbuff_append(buff, p);
free(p);
xbt_strbuff_append(buff, p);
free(p);