}
/** Helper function to obtain valid strings from possibly null input. */
-static const char *valid_string(const char *input)
+static inline const char *valid_string(const char *input)
{
- if (input != NULL)
- return input;
- else
- return "";
+ return (input) ? input : "";
}
/** Helper function to convert between map<string, VariantBase> and GHashTable */
Context::Context() :
UserOwned(_structure),
- _session(NULL)
+ _session(nullptr)
{
check(sr_init(&_structure));
static int call_log_callback(void *cb_data, int loglevel, const char *format, va_list args)
{
- va_list args_copy;
- va_copy(args_copy, args);
- int length = vsnprintf(NULL, 0, format, args_copy);
- va_end(args_copy);
- char *buf = (char *) g_malloc(length + 1);
- vsprintf(buf, format, args);
- string message(buf, length);
- g_free(buf);
+ const unique_ptr<char, decltype(&g_free)>
+ message {g_strdup_vprintf(format, args), &g_free};
LogCallbackFunction callback = *((LogCallbackFunction *) cb_data);
try
{
- callback(LogLevel::get(loglevel), message);
+ callback(LogLevel::get(loglevel), message.get());
}
catch (Error e)
{
map<string, string> Context::serials(shared_ptr<Driver> driver)
{
- GSList *serial_list = sr_serial_list(driver ? driver->_structure : NULL);
+ GSList *serial_list = sr_serial_list(driver ? driver->_structure : nullptr);
map<string, string> serials;
for (GSList *serial = serial_list; serial; serial = serial->next) {
Driver::Driver(struct sr_dev_driver *structure) :
ParentOwned(structure),
- Configurable(structure, NULL, NULL),
+ Configurable(structure, nullptr, nullptr),
_initialized(false)
{
}
}
/* Translate scan options to GSList of struct sr_config pointers. */
- GSList *option_list = NULL;
+ GSList *option_list = nullptr;
for (auto entry : options)
{
auto key = entry.first;
}
Device::Device(struct sr_dev_inst *structure) :
- Configurable(sr_dev_inst_driver_get(structure), structure, NULL),
+ Configurable(sr_dev_inst_driver_get(structure), structure, nullptr),
_structure(structure)
{
for (GSList *entry = sr_dev_inst_channels_get(structure); entry; entry = entry->next)
{
if (!trigger)
// Set NULL trigger, i.e. remove any trigger from the session.
- check(sr_session_trigger_set(_structure, NULL));
+ check(sr_session_trigger_set(_structure, nullptr));
else
check(sr_session_trigger_set(_structure, trigger->_structure));
_trigger = move(trigger);
Output::Output(shared_ptr<OutputFormat> format,
shared_ptr<Device> device, const map<string, Glib::VariantBase> &options) :
UserOwned(sr_output_new(format->_structure,
- map_to_hash_variant(options), device->_structure, NULL)),
+ map_to_hash_variant(options), device->_structure, nullptr)),
_format(move(format)),
_device(move(device)),
_options(options)