History

compat/cuda/ptx2c: remove bashism and harden against arbitrary input

Timo Rothenpieler committed 9 years ago

Commit 88896c41 parent f0435bb1 file · +6 −6Browse files

Showing the changes to compat (1 of 1 file). Show all

Unified · Split

compat/cuda/ptx2c.sh+6−6
@@ -1,3 +1,5 @@
1+#!/bin/sh
2+
13 # Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
24 #
35 # Permission is hereby granted, free of charge, to any person obtaining a
@@ -22,15 +24,13 @@ set -e · 18 unmodified lines
2224
2325 OUT="$1"
2426 IN="$2"
25−NAME="$(basename "$IN")"
26−NAME="${NAME/.ptx/}"
27+NAME="$(basename "$IN" | sed 's/\..*//')"
2728
28−echo -n "const char ${NAME}_ptx[] = \\" > "$OUT"
29+printf "const char %s_ptx[] = \\" "$NAME" > "$OUT"
2930 while read LINE
3031 do
31−echo -ne "\n\t\"$LINE\\\n\"" >> "$OUT"
32+ printf "\n\t\"%s\\\n\"" "$(printf "%s" "$LINE" | sed 's/["\\]/\\&/g')" >> "$OUT"
3233 done < "$IN"
33−echo ";" >> "$OUT"
34+printf ";\n" >> "$OUT"
3435
3536 exit 0
36−

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t