flash/stm32l4x: prevent undefined behavior warnings caused by signed integer operations
[fw/openocd] / src / flash / nor / stmsmi.c
index f633e361924d4a0165e6d58f51234d9de32dbbc5..553bf2924af8c0dfdf1a465f8e0c1f552718a4c0 100644 (file)
@@ -144,7 +144,7 @@ FLASH_BANK_COMMAND_HANDLER(stmsmi_flash_bank_command)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        stmsmi_info = malloc(sizeof(struct stmsmi_flash_bank));
-       if (stmsmi_info == NULL) {
+       if (!stmsmi_info) {
                LOG_ERROR("not enough memory");
                return ERROR_FAIL;
        }
@@ -600,7 +600,7 @@ static int stmsmi_probe(struct flash_bank *bank)
        bank->num_sectors =
                stmsmi_info->dev->size_in_bytes / sectorsize;
        sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
-       if (sectors == NULL) {
+       if (!sectors) {
                LOG_ERROR("not enough memory");
                return ERROR_FAIL;
        }
@@ -631,17 +631,16 @@ static int stmsmi_protect_check(struct flash_bank *bank)
        return ERROR_OK;
 }
 
-static int get_stmsmi_info(struct flash_bank *bank, char *buf, int buf_size)
+static int get_stmsmi_info(struct flash_bank *bank, struct command_invocation *cmd)
 {
        struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv;
 
        if (!(stmsmi_info->probed)) {
-               snprintf(buf, buf_size,
-                       "\nSMI flash bank not probed yet\n");
+               command_print_sameline(cmd, "\nSMI flash bank not probed yet\n");
                return ERROR_OK;
        }
 
-       snprintf(buf, buf_size, "\nSMI flash information:\n"
+       command_print_sameline(cmd, "\nSMI flash information:\n"
                "  Device \'%s\' (ID 0x%08" PRIx32 ")\n",
                stmsmi_info->dev->name, stmsmi_info->dev->device_id);