u8 bootmode;
const char *mode;
char *new_targets;
+ char *env_targets;
int ret;
if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
* One terminating char + one byte for space between mode
* and default boot_targets
*/
- new_targets = calloc(1, strlen(mode) +
- strlen(env_get("boot_targets")) + 2);
+ env_targets = env_get("boot_targets");
+ if (env_targets) {
+ new_targets = calloc(1, strlen(mode) +
+ strlen(env_targets) + 2);
+ sprintf(new_targets, "%s %s", mode, env_targets);
+ } else {
+ new_targets = calloc(1, strlen(mode) + 2);
+ sprintf(new_targets, "%s", mode);
+ }
- sprintf(new_targets, "%s %s", mode, env_get("boot_targets"));
env_set("boot_targets", new_targets);
return 0;