- &index, name, &bitness) == 3) {
- at_least_one_syscall = true;
- if (index >= nbmem) {
- struct syscall *new_list;
- size_t new_nbmem;
-
- /* Double memory size. */
- new_nbmem = std::max(index + 1, nbmem << 1);
- if (new_nbmem > (SIZE_MAX / sizeof(*new_list))) {
- /* Overflow, stop everything, something went really wrong. */
- ERR("Syscall listing memory size overflow. Stopping");
- free(syscall_table);
- syscall_table = NULL;
- ret = -EINVAL;
- goto error;
- }
-
- DBG("Reallocating syscall table from %zu to %zu entries", nbmem,
- new_nbmem);
- new_list = (struct syscall *) realloc(syscall_table, new_nbmem * sizeof(*new_list));
- if (!new_list) {
- ret = -errno;
- PERROR("syscall list realloc");
- goto error;
- }
-
- /* Zero out the new memory. */
- memset(new_list + nbmem, 0,
- (new_nbmem - nbmem) * sizeof(*new_list));
- nbmem = new_nbmem;
- syscall_table = new_list;
- }
- syscall_table[index].index = index;
- syscall_table[index].bitness = bitness;
- if (lttng_strncpy(syscall_table[index].name, name,
- sizeof(syscall_table[index].name))) {
- ret = -EINVAL;
- free(syscall_table);
- syscall_table = NULL;
+ &index,
+ name,
+ &bitness) == 3) {
+ try {
+ syscall_table.emplace_back(index, bitness, name);
+ } catch (const std::bad_alloc&) {
+ ERR_FMT("Failed to add syscall to syscall table: table_current_element_count={}, syscall_name=`{}`",
+ syscall_table.size(),
+ name);
+ ret = ENOMEM;
+ goto error;
+ } catch (const lttng::invalid_argument_error& ex) {
+ ERR_FMT("Failed to add syscall to syscall table: table_current_element_count={}, reason=`{}`",
+ syscall_table.size(),
+ name,
+ ex.what());
+ ret = EINVAL;