target: fix segmentation fault on target create
commitd4575b647a3603200a9bb4a784d170f792ab88d0
authorAntonio Borneo <borneo.antonio@gmail.com>
Sun, 5 Nov 2023 16:02:26 +0000 (5 17:02 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 18 Nov 2023 11:16:27 +0000 (18 11:16 +0000)
treee1858210ef7aa136f4fc7e3aee533dde829f9286
parentb39072f2ef72f02601b40931d3a38c465804a906
target: fix segmentation fault on target create

In the unusual (and even incorrect) case of running the command
target create ...
before defining an adapter and the associated transport, the
command causes a segmentation fault. E.g.:
openocd -c 'target create cpu cortex-m -endian little'

Check that get_current_transport() returns a valid pointer before
referencing it.

Change-Id: I9796a7e92196ef3df5c7152b27c34102045dc9e7
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7962
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
src/target/target.c