I have an idea how you could debug it yourself. Place "Message" statements between the lines of your code that would print something meaningful to you into the console like
Now if it segfaults before the Message-line, your UDF won't print the string "after T_cell assignment" into the console. Consequently, if you see the string printed, then the line that causes the segfault is further down below in the program listing.
This way you can isolate the problematic line. Then have a think what could be wrong with it.